diff --git a/frontend/src/pages/+guard.ts b/frontend/src/pages/+guard.ts index 4e84dd7da9..f4d679f9f1 100644 --- a/frontend/src/pages/+guard.ts +++ b/frontend/src/pages/+guard.ts @@ -1,13 +1,17 @@ import { redirect } from 'vike/abort' +import pinia from '#plugins/pinia' import { AUTH } from '#src/env' +import { useAuthStore } from '#stores/authStore' import type { GuardSync } from 'vike/types' const guard: GuardSync = (pageContext): ReturnType => { - console.log('guard', pageContext.hasToken) - if (!pageContext.hasToken) { - // throw redirect(AUTH.UNAUTHORIZED_REDIRECT_URI) + // the store is the client side part, pageContext the serverSide part + // there might be a better solution to combine both into pageContext + const authStore = useAuthStore(pinia) + if (!pageContext.hasToken && !authStore.isLoggedIn) { + throw redirect(AUTH.UNAUTHORIZED_REDIRECT_URI) } }