Skip to content

Commit

Permalink
fix guard for client side rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfgebhardt committed Apr 10, 2024
1 parent 52d20f7 commit fe451f8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions frontend/src/pages/+guard.ts
Original file line number Diff line number Diff line change
@@ -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<GuardSync> => {
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)
}
}

Expand Down

0 comments on commit fe451f8

Please sign in to comment.