Skip to content

Commit

Permalink
feat: add expires_at validation in #_saveSession()
Browse files Browse the repository at this point in the history
  • Loading branch information
hf committed Jul 5, 2023
1 parent 0f04bfc commit 180bec7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ export default class GoTrueClient {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (error) {
return { data: { user: null, session: null }, error }
} else if (!data || !data.session || !data.user) {
} else if (!data || !data.session || !data.user || !data.expires_at) {
return { data: { user: null, session: null }, error: new AuthInvalidTokenResponseError() }
}
if (data.session) {
Expand Down Expand Up @@ -521,7 +521,7 @@ export default class GoTrueClient {
const { data, error } = res
if (error) {
return { data: { user: null, session: null }, error }
} else if (!data || !data.session || !data.user) {
} else if (!data || !data.session || !data.user || !data.expires_at) {
return {
data: { user: null, session: null },
error: new AuthInvalidTokenResponseError(),
Expand Down Expand Up @@ -1491,7 +1491,13 @@ export default class GoTrueClient {
this.inMemorySession = session
}

if (this.persistSession && session.expires_at) {
if (this.persistSession) {
if (!session.expires_at) {
throw new Error(
`GoTrueClient#_saveSession() requires a session with the expires_at field set`
)
}

await this._persistSession(session)
}
}
Expand Down Expand Up @@ -1852,8 +1858,8 @@ export default class GoTrueClient {
}

await this._saveSession({
expires_at: Math.round(Date.now() / 1000) + data.expires_in,
...data,
expires_at: Math.round(Date.now() / 1000) + data.expires_in,
})
await this._notifyAllSubscribers('MFA_CHALLENGE_VERIFIED', data)

Expand Down

0 comments on commit 180bec7

Please sign in to comment.