supabase
supabase copied to clipboard
Auth session null in ssr, only gets populated in client
Hello, I have a very basic login form, which is shown when the user is not logged in (I'm using magic link logins). The problem is, my website always shows the login form first then the client js starts up and it shows the content.
I also tried switching of js completely in my browser and it shows the expected result. On ther server side rendered website there's no user session. It can also be seen, when using console.log.
const { auth } = useSupabaseAuthClient()
// { data: { session: null }, error: null } on server side rendering
const session = await auth.getSession()
console.log(session)
Any idea why there is no user session in SSR?
My browser sends the sb-access-token and sb-refresh-token to the server with the request, but the serverside supabase doesn't seem to use them.
When using getUser() it works and I get a user object. But getSession doesn't return any session :/
useAsyncData(async () => await auth.getUser())
I’m not sure if this is related but the session only gets populated after the app mounts. I had a similar question in #161
Small write up here: https://medium.com/@thexumaker/trouble-accessing-your-session-and-access-token-using-supabase-nuxt-and-vue3-e03e6b979bbf
Oh that sounds interesting and would explain the behavior. I guess I'll have to use the less performant getUser() then, because that actually works on the server side, I think :D