diff options
| author | 2025-09-21 01:13:25 +0000 | |
|---|---|---|
| committer | 2025-09-21 01:13:25 +0000 | |
| commit | 9d26295c65d2c68ae5012bea1b20ea7e45e93325 (patch) | |
| tree | 3616eccafc248e25eb7f0e8c93e15b2863e8a502 /src/routes/api | |
| parent | 11877824040ed2b92dab0efe04d7b24c64fa39cd (diff) | |
| download | crunched-master.tar.gz crunched-master.tar.bz2 crunched-master.tar.lz crunched-master.zip | |
Diffstat (limited to 'src/routes/api')
| -rw-r--r-- | src/routes/api/v1/vms/list/+server.ts | 12 | ||||
| -rw-r--r-- | src/routes/api/v1/whoami/+server.ts | 40 |
2 files changed, 49 insertions, 3 deletions
diff --git a/src/routes/api/v1/vms/list/+server.ts b/src/routes/api/v1/vms/list/+server.ts new file mode 100644 index 0000000..7bbf8f3 --- /dev/null +++ b/src/routes/api/v1/vms/list/+server.ts @@ -0,0 +1,12 @@ +import { error, json } from '@sveltejs/kit'; +import { 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({ + todo: 'implement', + }); +}; 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', + }); }; |