question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getServerSession SSR results in invalid refresh token

See original GitHub issue

Bug report

Describe the bug

When enabling SSR in SvelteKit and utilising the getServerSession(event) function to pull the session from the request cookies - there seems to be a race condition in which the server will refresh the token, and not pass the updated session to the client. This causes the client to attempt to refresh the session and receive an invalid refresh token response, which then wipes the client-side cookies and any authentication state.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Enable SSR in sveltekit with getServerSession

Expected behavior

Potentially leave any token refreshing to the client

Screenshots

If applicable, add screenshots to help explain your problem. Screenshot 2022-10-26 at 18 20 08@2x

I’ve seen some docs here: https://github.com/supabase/supabase/blob/df506a9a07eb114ceefa3801479ebdf009bf08fb/apps/reference/docs/guides/auth/server-side-rendering.mdx

But it doesn’t seem to apply to my case - it seems like the server is automatically refreshing the tokens causing the clientside to fail

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
david-pluggecommented, Oct 26, 2022

Okay this is actually pretty weird. The client does not call the sveltekit server to refresh the tokens therefore there must be an error on the client side. I´ll take a deeper look into this

1reaction
david-pluggecommented, Oct 27, 2022

I´ve found the cause, one instance of the supabaseClient on the server had autoRefreshToken enabled.

Thanks for reporting the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

next-auth.session-token invalid signature on jwt.io
I followed a video and tried copy my session token to jwt.io to see it, but all i get is an error saying...
Read more >
Client API - NextAuth.js
The session data returned to the client does not contain sensitive information such as the Session Token or OAuth tokens.
Read more >
Server-Side Rendering - Supabase
My server is getting invalid refresh token errors. What's going on?#. It is likely that the refresh token sent from the browser to...
Read more >
Next.js Authentication - JWT Refresh Token Rotation with ...
It will be used to obtain new accessTokens . The accessTokenExpiry is a timestamp of when the token becomes invalid. It can also...
Read more >
NextJS SSR - JWT (Access/Refresh Token) Authentication ...
In this article we will cover how to do it using access token + refresh token ... As a result, you face one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found