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

fix: don't refresh session if autoRefreshToken setting is set to false #925

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ export default class GoTrueClient {
}

const { session, error } = await this._callRefreshToken(currentSession.refresh_token)

if (error) {
return { data: { session: null }, error }
}
Expand Down Expand Up @@ -1293,6 +1294,10 @@ export default class GoTrueClient {
}

if (hasExpired) {
if (!this.autoRefreshToken) {
return { data: { user: null, session: null }, error: null }
}

const { session: refreshedSession, error } = await this._callRefreshToken(
currentSession.refresh_token
)
Expand All @@ -1303,12 +1308,15 @@ export default class GoTrueClient {
if (!refreshedSession) {
return { data: { user: null, session: null }, error: null }
}

session = refreshedSession
} else {
const { data, error } = await this._getUser(currentSession.access_token)

if (error) {
throw error
}

session = {
access_token: currentSession.access_token,
refresh_token: currentSession.refresh_token,
Expand Down