Skip to content

Commit

Permalink
fix: use keyed auth state
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 25, 2023
1 parent 51ece88 commit a42f735
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/runtime/plugin.ts
Expand Up @@ -7,14 +7,15 @@ import {
import type { UserType } from '@kinde-oss/kinde-typescript-sdk'

export default defineNuxtPlugin(async () => {
const state = useState<{ loggedIn: true, user: UserType } | { loggedIn: false, user: null }>(shallowRef)
const state = useState<{ loggedIn: true, user: UserType } | { loggedIn: false, user: null }>('auth', shallowRef)
if (import.meta.server) {
const isLoggedIn = await useRequestEvent().context.kinde.isAuthenticated()
const event = useRequestEvent()
const isLoggedIn = await event.context.kinde.isAuthenticated()

state.value = {
loggedIn: isLoggedIn,
user: isLoggedIn
? await useRequestEvent().context.kinde.getUserProfile()
? await event.context.kinde.getUserProfile()
: null,
} as { loggedIn: true, user: UserType } | { loggedIn: false, user: null }
}
Expand Down

0 comments on commit a42f735

Please sign in to comment.