Skip to content

Commit 5034d6f

Browse files
committed
fix: call realtime and auth setAuth on initial SIGNED_IN event
1 parent c11e7de commit 5034d6f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/SupabaseClient.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default class SupabaseClient {
3636
protected realtime: RealtimeClient
3737
protected multiTab: boolean
3838
protected fetch?: Fetch
39+
protected changedAccessToken: string | undefined
3940

4041
/**
4142
* Create a new client for use in the browser.
@@ -266,19 +267,21 @@ export default class SupabaseClient {
266267
token: string | undefined,
267268
source: 'CLIENT' | 'STORAGE'
268269
) {
269-
if (token == this.auth.session()?.access_token) {
270-
// Token is unchanged
271-
return null
272-
} else if (event === 'SIGNED_OUT' || event === 'USER_DELETED') {
273-
// Token is removed
274-
this.removeAllSubscriptions()
275-
if (source == 'STORAGE') this.auth.signOut()
276-
} else if (event === 'TOKEN_REFRESHED' || event === 'SIGNED_IN') {
270+
if (
271+
(event === 'TOKEN_REFRESHED' || event === 'SIGNED_IN') &&
272+
this.changedAccessToken !== token
273+
) {
277274
// Token has changed
278275
this.realtime.setAuth(token!)
279276
// Ideally we should call this.auth.recoverSession() - need to make public
280277
// to trigger a "SIGNED_IN" event on this client.
281278
if (source == 'STORAGE') this.auth.setAuth(token!)
279+
280+
this.changedAccessToken = token
281+
} else if (event === 'SIGNED_OUT' || event === 'USER_DELETED') {
282+
// Token is removed
283+
this.removeAllSubscriptions()
284+
if (source == 'STORAGE') this.auth.signOut()
282285
}
283286
}
284287
}

0 commit comments

Comments
 (0)