Update dependencies, change generate token based on new lucia method, and replace fails.

This commit is contained in:
Bradley Shellnut 2024-04-25 11:26:05 -07:00
parent 085cb2ef27
commit a7474cbbbd
5 changed files with 284 additions and 456 deletions

View file

@ -22,7 +22,7 @@
}, },
"devDependencies": { "devDependencies": {
"@melt-ui/pp": "^0.3.1", "@melt-ui/pp": "^0.3.1",
"@melt-ui/svelte": "^0.76.3", "@melt-ui/svelte": "^0.77.0",
"@playwright/test": "^1.43.1", "@playwright/test": "^1.43.1",
"@resvg/resvg-js": "^2.6.2", "@resvg/resvg-js": "^2.6.2",
"@sveltejs/adapter-auto": "^3.2.0", "@sveltejs/adapter-auto": "^3.2.0",
@ -52,21 +52,21 @@
"satori": "^0.10.13", "satori": "^0.10.13",
"satori-html": "^0.3.2", "satori-html": "^0.3.2",
"svelte": "^4.2.15", "svelte": "^4.2.15",
"svelte-check": "^3.6.9", "svelte-check": "^3.7.0",
"svelte-headless-table": "^0.18.2", "svelte-headless-table": "^0.18.2",
"svelte-meta-tags": "^3.1.2", "svelte-meta-tags": "^3.1.2",
"svelte-preprocess": "^5.1.4", "svelte-preprocess": "^5.1.4",
"svelte-sequential-preprocessor": "^2.0.1", "svelte-sequential-preprocessor": "^2.0.1",
"sveltekit-flash-message": "^2.4.4", "sveltekit-flash-message": "^2.4.4",
"sveltekit-rate-limiter": "^0.5.1", "sveltekit-rate-limiter": "^0.5.1",
"sveltekit-superforms": "^2.12.5", "sveltekit-superforms": "^2.12.6",
"tailwindcss": "^3.4.3", "tailwindcss": "^3.4.3",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"tslib": "^2.6.1", "tslib": "^2.6.1",
"tsx": "^4.7.2", "tsx": "^4.7.3",
"typescript": "^5.4.4", "typescript": "^5.4.4",
"vite": "^5.2.10", "vite": "^5.2.10",
"vitest": "^1.4.0", "vitest": "^1.5.2",
"zod": "^3.23.4" "zod": "^3.23.4"
}, },
"type": "module", "type": "module",
@ -98,8 +98,8 @@
"just-capitalize": "^3.2.0", "just-capitalize": "^3.2.0",
"just-kebab-case": "^4.2.0", "just-kebab-case": "^4.2.0",
"loader": "^2.1.1", "loader": "^2.1.1",
"lucia": "3.1.1", "lucia": "3.2.0",
"lucide-svelte": "^0.368.0", "lucide-svelte": "^0.373.0",
"open-props": "^1.7.3", "open-props": "^1.7.3",
"oslo": "^1.2.0", "oslo": "^1.2.0",
"pg": "^8.11.5", "pg": "^8.11.5",

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,17 @@
import db from "$lib/drizzle"; import { generateIdFromEntropySize } from 'lucia';
import { eq } from "drizzle-orm"; import { TimeSpan, createDate } from 'oslo';
import { generateId } from "lucia"; import { eq } from 'drizzle-orm';
import { TimeSpan, createDate } from "oslo"; import db from '$lib/drizzle';
import { password_reset_tokens } from "../../schema"; import { password_reset_tokens } from '../../schema';
export async function createPasswordResetToken(userId: string): Promise<string> { export async function createPasswordResetToken(userId: string): Promise<string> {
// optionally invalidate all existing tokens // optionally invalidate all existing tokens
await db.delete(password_reset_tokens).where(eq(password_reset_tokens.user_id, userId)); await db.delete(password_reset_tokens).where(eq(password_reset_tokens.user_id, userId));
const tokenId = generateId(40); const tokenId = generateIdFromEntropySize(40);
await db await db.insert(password_reset_tokens).values({
.insert(password_reset_tokens) id: tokenId,
.values({ user_id: userId,
id: tokenId, expires_at: createDate(new TimeSpan(2, 'h')),
user_id: userId, });
expires_at: createDate(new TimeSpan(2, "h"))
});
return tokenId; return tokenId;
} }

View file

@ -176,4 +176,4 @@ export type SearchQuery = {
fields?: string; fields?: string;
}; };
export type UICollection = Pick<typeof collections, 'id' | 'cuid' | 'name'>; export type UICollection = Pick<typeof collections, 'cuid' | 'name'>;

View file

@ -1,4 +1,4 @@
import { type Actions, error } from '@sveltejs/kit'; import { type Actions, error, fail } from '@sveltejs/kit';
import { and, eq } from 'drizzle-orm'; import { and, eq } from 'drizzle-orm';
import { zod } from 'sveltekit-superforms/adapters'; import { zod } from 'sveltekit-superforms/adapters';
import { superValidate } from 'sveltekit-superforms/server'; import { superValidate } from 'sveltekit-superforms/server';
@ -33,7 +33,7 @@ export async function load(event) {
const searchForm = await superValidate(searchData, zod(search_schema)); const searchForm = await superValidate(searchData, zod(search_schema));
const listManageForm = await superValidate(zod(modifyListGameSchema)); const listManageForm = await superValidate(zod(modifyListGameSchema));
const collection: UICollection | undefined = await db.query.collections.findFirst({ const collection = await db.query.collections.findFirst({
columns: { columns: {
id: true, id: true,
cuid: true, cuid: true,
@ -91,7 +91,10 @@ export async function load(event) {
return { return {
searchForm, searchForm,
listManageForm, listManageForm,
collection, collection: {
name: collection.name,
cuid: collection.cuid ?? '',
},
items, items,
}; };
} }
@ -102,7 +105,7 @@ export const actions: Actions = {
const form = await superValidate(event, zod(modifyListGameSchema)); const form = await superValidate(event, zod(modifyListGameSchema));
if (!event.locals.user) { if (!event.locals.user) {
throw fail(401); return fail(401, {});
} }
const user = event.locals.user; const user = event.locals.user;
@ -147,14 +150,14 @@ export const actions: Actions = {
// Create new wishlist // Create new wishlist
create: async ({ locals }) => { create: async ({ locals }) => {
if (!locals.user) { if (!locals.user) {
throw fail(401); return fail(401);
} }
return error(405, 'Method not allowed'); return error(405, 'Method not allowed');
}, },
// Delete a wishlist // Delete a wishlist
delete: async ({ locals }) => { delete: async ({ locals }) => {
if (!locals.user) { if (!locals.user) {
throw fail(401); return fail(401);
} }
return error(405, 'Method not allowed'); return error(405, 'Method not allowed');
}, },
@ -164,7 +167,7 @@ export const actions: Actions = {
const form = await superValidate(event, zod(modifyListGameSchema)); const form = await superValidate(event, zod(modifyListGameSchema));
if (!locals.user) { if (!locals.user) {
throw fail(401); return fail(401);
} }
const game = await db.query.games.findFirst({ const game = await db.query.games.findFirst({