Christmas cookie ranking site
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix #11: save name as correct case in session

+15 -7
+2 -2
generated/schema.sql
··· 2 2 -- PostgreSQL database dump 3 3 -- 4 4 5 - -- Dumped from database version 17.0 (Debian 17.0-1.pgdg120+1) 6 - -- Dumped by pg_dump version 17.0 (Debian 17.0-1.pgdg120+1) 5 + -- Dumped from database version 17.5 (Debian 17.5-1.pgdg120+1) 6 + -- Dumped by pg_dump version 17.5 (Debian 17.5-1.pgdg120+1) 7 7 8 8 SET statement_timeout = 0; 9 9 SET lock_timeout = 0;
+13 -5
src/routes/login/+page.server.ts
··· 12 12 if (!account_id) return fail(400, { error: "Your name is required" }); 13 13 14 14 try { 15 - const created = await locals.database.one<Pick<Account, "id">>( 16 - sql.query`INSERT INTO accounts (id) VALUES (${sql.value(account_id)}) ON CONFLICT DO NOTHING RETURNING id`, 17 - ); 18 - locals.account = account_id; 15 + const account = 16 + (await locals.database.one<Pick<Account, "id">>( 17 + sql.query`SELECT id FROM accounts WHERE id = ${sql.value(account_id)}`, 18 + )) ?? 19 + (await locals.database.one<Pick<Account, "id">>( 20 + sql.query`INSERT INTO accounts (id) VALUES (${sql.value(account_id)}) RETURNING id`, 21 + )); 22 + if (!account) throw new TypeError("Account not found or created"); 23 + locals.account = account.id; 19 24 } catch (error) { 20 25 if ( 21 26 error instanceof pg.DatabaseError && ··· 24 29 ) { 25 30 return fail(400, { action: "login" as const, message: "Name is too long" }); 26 31 } 27 - return fail(500, { action: "login" as const, message: "Something went wrong" }); 32 + return fail(500, { 33 + action: "login" as const, 34 + message: (error as Error).message ?? "Something went wrong", 35 + }); 28 36 } 29 37 redirect(303, to); 30 38 },