Skip to content

Commit

Permalink
feat: function for checking authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMysterius committed Sep 2, 2024
1 parent eab1682 commit be97eab
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/server/functions/isAuthed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { json, type RequestEvent } from '@sveltejs/kit';

export function isAuthed(e: RequestEvent) {
if (!e.locals.auth.isAuthed) {
if (e.locals.auth.isATExpired && !e.locals.auth.isRTExpired) {
return json({ message: 'Current Access Token Expired' }, { status: 401 });
}

return json({ message: 'Unauthorized Request' }, { status: 401 });
}

return;
}

0 comments on commit be97eab

Please sign in to comment.