@@ -118,11 +118,13 @@ export default class SupabaseClient<
118118 }
119119
120120 this . fetch = fetchWithAuth ( supabaseKey , this . _getAccessToken . bind ( this ) , settings . global . fetch )
121+
121122 this . realtime = this . _initRealtimeClient ( {
122123 headers : this . headers ,
123124 accessToken : this . _getAccessToken . bind ( this ) ,
124125 ...settings . realtime ,
125126 } )
127+
126128 this . rest = new PostgrestClient ( `${ _supabaseUrl } /rest/v1` , {
127129 headers : this . headers ,
128130 schema : settings . db . schema ,
@@ -320,14 +322,13 @@ export default class SupabaseClient<
320322 } )
321323 }
322324
323- private _listenForAuthEvents ( ) {
324- let data = this . auth . onAuthStateChange ( ( event , session ) => {
325- this . _handleTokenChanged ( event , 'CLIENT' , session ?. access_token )
325+ private async _listenForAuthEvents ( ) {
326+ return await this . auth . onAuthStateChange ( async ( event , session ) => {
327+ await this . _handleTokenChanged ( event , 'CLIENT' , session ?. access_token )
326328 } )
327- return data
328329 }
329330
330- private _handleTokenChanged (
331+ private async _handleTokenChanged (
331332 event : AuthChangeEvent ,
332333 source : 'CLIENT' | 'STORAGE' ,
333334 token ?: string
@@ -338,7 +339,7 @@ export default class SupabaseClient<
338339 ) {
339340 this . changedAccessToken = token
340341 } else if ( event === 'SIGNED_OUT' ) {
341- this . realtime . setAuth ( )
342+ await this . realtime . setAuth ( )
342343 if ( source == 'STORAGE' ) this . auth . signOut ( )
343344 this . changedAccessToken = undefined
344345 }
0 commit comments