How to get session from a SSR application?
Maybe I'm missing something, but this feels like a bug.
I have a Remix project and from the advice on Github, I created a SupabaseClient per route request by passing the users accessToken to
global.headers
With this configuration, unfortunately, I'm unable to get session or user. Is this expected?
More details in the issue I reported: https://github.com/supabase/gotrue-js/issues/450
P.S. Too many auth issues with supabase... It's a bit concerning. Hopefully this is an oversight on my endGitHub
GoTrueClient is unable to retrieve session when setting accessToken...
Bug report Describe the bug After removing setAuth it's recommend to set an accessToken via global.headers. Here's an example: #340 (comment) Unfortunately, this breaks auth functio...
2 Replies
Seems dropping setAuth keeps leading to issues.
But it is not clear setAuth did before what you think anyway.
All it was documented to do was
Overrides the JWT on the current client. The JWT will then be sent in all subsequent network requests.
Although it does/did update the session variable with the jwt, it does not actually change the user object. this.user() would still be what ever user info was there before if any.... IF I READ IT CORRECTLY.
But posting your issue and linking to the setAuth discussion hopefully brings more focus on the impact of the change.you're right, it was just an inline change to access token.
What I had to do to get a user was to call
supabase.auth.api.getUser(session.get('access_token'))
supabase.auth.api
was removed in v2. I presumed in favor of supabase.auth.getUser
. But of course getUser does not work.
--
Hopefully we'll get some eyes on this, but I decided to downgrade back to v1 and make sure a SupabaseClient is created per route request
That at least was clear to me. I originally had a Remix setup with a global supabase client, but since it's reused across multiple request it didn't make sense. Now I've made it so each request handles it's own supabase client