supabase icon indicating copy to clipboard operation
supabase copied to clipboard

Auth session null in ssr, only gets populated in client

Open supermar1010 opened this issue 2 years ago • 3 comments

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.

supermar1010 avatar Feb 22 '23 14:02 supermar1010

When using getUser() it works and I get a user object. But getSession doesn't return any session :/

useAsyncData(async () => await auth.getUser())

supermar1010 avatar Feb 26 '23 13:02 supermar1010

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

Thexumaker avatar Feb 26 '23 17:02 Thexumaker

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

supermar1010 avatar Mar 01 '23 20:03 supermar1010