Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access token refresh not working #58

Closed
saschatimme opened this issue Dec 23, 2022 · 5 comments
Closed

Access token refresh not working #58

saschatimme opened this issue Dec 23, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@saschatimme
Copy link

saschatimme commented Dec 23, 2022

The refreshAccessToken function calls into supabase-js using

const { data, error } = await getSupabaseAdmin().auth.setSession({
access_token: "",
refresh_token: refreshToken,
});

(note access_token: "")
However, inside supabase we hit the code path

/**
   * Sets the session data from the current session. If the current session is expired, setSession will take care of refreshing it to obtain a new session.
   * If the refresh token or access token in the current session is invalid, an error will be thrown.
   * @param currentSession The current session that minimally contains an access token and refresh token.
   */
  async setSession(currentSession: {
    access_token: string
    refresh_token: string
  }): Promise<AuthResponse> {
    try {
      if (!currentSession.access_token || !currentSession.refresh_token) {
        throw new AuthSessionMissingError()
      }

So the code always errors (file can be found at node_modules/.pnpm/@supabase+gotrue-js@2.6.1/node_modules/@supabase/gotrue-js/src/GoTrueClient.ts lines 626 and following)

@saschatimme
Copy link
Author

saschatimme commented Dec 23, 2022

Just dig a little bit more around and found that there is also the getSupabaseAdmin().auth.refreshSession function that only requires a refresh token? Was maybe the intention to call this?

@rphlmr
Copy link
Owner

rphlmr commented Dec 23, 2022

Hello, thanks for your report.
In production, I'm on a later version of supabase with no error.

This code was a hack when 2.0 was released and It seems they get back us a refreshSession.

Will try to fix that after Christmas 🎄

@rphlmr rphlmr added the bug Something isn't working label Dec 23, 2022
@saschatimme
Copy link
Author

Thanks for the quick response!

You mean an earlier version right? This is appearing in the latest versions of supabase-js (2.2.1) and @supabase/gotrue-js (2.6.1).

Appreciate that you will take a look :) Happy holidays 🎄

@barbinbrad
Copy link

For reference: supabase/supabase#9847 (comment)

@rphlmr
Copy link
Owner

rphlmr commented Jan 2, 2023

Thank you all, it should be fixed now.
Will try that on production next week, but seems fine on paper.

I wish you a happy new year :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants