Skip to content

Commit f2e2882

Browse files
committed
make it await for setAuth
1 parent 4cc9526 commit f2e2882

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/SupabaseClient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,19 @@ export default class SupabaseClient<
318318
}
319319

320320
private _listenForAuthEvents() {
321-
let data = this.auth.onAuthStateChange((event, session) => {
322-
this._handleTokenChanged(event, 'CLIENT', session?.access_token)
321+
let data = this.auth.onAuthStateChange(async (event, session) => {
322+
await this._handleTokenChanged(event, 'CLIENT', session?.access_token)
323323
})
324324
return data
325325
}
326326

327-
private _handleTokenChanged(
327+
private async _handleTokenChanged(
328328
event: AuthChangeEvent,
329329
source: 'CLIENT' | 'STORAGE',
330330
token?: string
331331
) {
332-
this.realtime.setAuth()
332+
// On any token change we call the realtime setAuth function that it's by itself a callback and lets Realtime run the flow needed by it.
333+
await this.realtime.setAuth()
333334
if (
334335
(event === 'TOKEN_REFRESHED' || event === 'SIGNED_IN') &&
335336
this.changedAccessToken !== token

0 commit comments

Comments
 (0)