Skip to content

Commit

Permalink
fix: revert set auth call (#1331)
Browse files Browse the repository at this point in the history
This reverts commit 5e1e477.
  • Loading branch information
filipecabaco authored Dec 11, 2024
1 parent 5e1e477 commit 1c5b626
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/SupabaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,26 +318,24 @@ export default class SupabaseClient<
}

private _listenForAuthEvents() {
let data = this.auth.onAuthStateChange(async (event, session) => {
await this._handleTokenChanged(event, 'CLIENT', session?.access_token)
let data = this.auth.onAuthStateChange((event, session) => {
this._handleTokenChanged(event, 'CLIENT', session?.access_token)
})
return data
}

private async _handleTokenChanged(
private _handleTokenChanged(
event: AuthChangeEvent,
source: 'CLIENT' | 'STORAGE',
token?: string
) {
// On token change, call Realtime's `setAuth` to sync auth and connections.
// Realtime handles token retrieval internally which may involve customizations, so we don't pass the token directly.
await this.realtime.setAuth()
if (
(event === 'TOKEN_REFRESHED' || event === 'SIGNED_IN') &&
this.changedAccessToken !== token
) {
this.changedAccessToken = token
} else if (event === 'SIGNED_OUT') {
this.realtime.setAuth()
if (source == 'STORAGE') this.auth.signOut()
this.changedAccessToken = undefined
}
Expand Down

0 comments on commit 1c5b626

Please sign in to comment.