diff options
fix: handle nonexistent sessions as missing scopes
| -rw-r--r-- | src/lib/auth.ts | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/lib/auth.ts b/src/lib/auth.ts index dd6b043..92b22a3 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -10,7 +10,7 @@ import { goto } from '$app/navigation'; * Check the return value of this, even if getScopeOnFail is true; navigating client-side may not stop thread immediately! */ export const checkScope = ( - session: ClientSession, + session: ClientSession | null | undefined, /** The scopes we want */ neededScopes: string[], /** Redirect to login page if the scopes aren't found */ @@ -18,7 +18,7 @@ export const checkScope = ( /** The target URL if redirecting */ next?: string ) => { - const scopes = session.tokens.scope?.split(' ') ?? []; + const scopes = session?.tokens.scope?.split(' ') ?? []; if (!neededScopes.find((v) => !scopes.includes(v))) return true; else if (getScopeOnFail) { const targetUrl = `${base}/login?${ |