Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/runtime/plugins/supabase.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ export default defineNuxtPlugin({
const currentSession = useSupabaseSession()
const currentUser = useSupabaseUser()

// In SPA mode, restore session from storage before auth middleware runs.
// This prevents a race condition where middleware checks session before it's hydrated.
// See: https://github.com/nuxt-modules/supabase/issues/496
if (!useSsrCookies) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the best value to check.

const { data } = await client.auth.getSession()
if (data.session) {
currentSession.value = data.session
}
}

// Populate user before each page load to ensure the user state is correctly set before the page is rendered
nuxtApp.hook('page:start', async () => {
const { data } = await client.auth.getClaims()
Expand Down
Loading