From 9d26295c65d2c68ae5012bea1b20ea7e45e93325 Mon Sep 17 00:00:00 2001 From: memdmp Date: Sun, 21 Sep 2025 01:13:25 +0000 Subject: feat: misc changes before hopefully actually starting --- src/routes/api/v1/whoami/+server.ts | 40 ++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'src/routes/api/v1/whoami') diff --git a/src/routes/api/v1/whoami/+server.ts b/src/routes/api/v1/whoami/+server.ts index 98809a4..2b7d430 100644 --- a/src/routes/api/v1/whoami/+server.ts +++ b/src/routes/api/v1/whoami/+server.ts @@ -3,7 +3,41 @@ import { filterSession, type Session } from '../../../../hooks.server.js'; export const GET = async ({ locals }) => { const data = (await locals.auth()) as Session; - if (data === undefined) throw error(403, 'Unauthorized'); - if (data === null) throw error(401, 'Session Expired'); - return json(filterSession(data)); + + // note: these return types are JUST for this endpoint - rely on status code exclusively for the actual meaning. + const headers = { + 'Access-Control-Allow-Origin': '*', + }; + if (data === undefined) + return json( + { + '': '', + kind: 'NOT_AUTHENTICATED' as const, + message: 'Unauthenticated', + }, + { + status: 403, + statusText: 'Forbidden', + headers, + } + ); + if (data === null) + return json( + { + '': '', + kind: 'EXPIRED' as const, + message: 'Session Expired', + }, + { + status: 401, + statusText: 'Unauthorized', + headers, + } + ); + + return json(filterSession(data), { + headers, + status: 200, + statusText: 'OK :3', + }); }; -- cgit v1.2.3