@@ -85,7 +85,7 @@ export default class SupabaseClient {
85
85
* @param params The parameters to pass to the function call.
86
86
*/
87
87
rpc < T = any > ( fn : string , params ?: object ) {
88
- let rest = this . _initPostgRESTClient ( )
88
+ const rest = this . _initPostgRESTClient ( )
89
89
return rest . rpc < T > ( fn , params )
90
90
}
91
91
@@ -97,12 +97,11 @@ export default class SupabaseClient {
97
97
removeSubscription ( subscription : RealtimeSubscription ) {
98
98
return new Promise ( async ( resolve ) => {
99
99
try {
100
- if ( ! subscription . isClosed ( ) ) {
101
- await this . _closeChannel ( subscription )
102
- }
103
- let openSubscriptions = this . realtime . channels . length
100
+ await this . _closeSubscription ( subscription )
101
+
102
+ const openSubscriptions = this . getSubscriptions ( ) . length
104
103
if ( ! openSubscriptions ) {
105
- let { error } = await this . realtime . disconnect ( )
104
+ const { error } = await this . realtime . disconnect ( )
106
105
if ( error ) return resolve ( { error } )
107
106
}
108
107
return resolve ( { error : null , data : { openSubscriptions } } )
@@ -112,6 +111,12 @@ export default class SupabaseClient {
112
111
} )
113
112
}
114
113
114
+ private async _closeSubscription ( subscription : RealtimeSubscription ) {
115
+ if ( ! subscription . isClosed ( ) ) {
116
+ await this . _closeChannel ( subscription )
117
+ }
118
+ }
119
+
115
120
/**
116
121
* Returns an array of all your subscriptions.
117
122
*/
@@ -152,8 +157,8 @@ export default class SupabaseClient {
152
157
}
153
158
154
159
private _getAuthHeaders ( ) : { [ key : string ] : string } {
155
- let headers : { [ key : string ] : string } = { }
156
- let authBearer = this . auth . session ( ) ?. access_token ?? this . supabaseKey
160
+ const headers : { [ key : string ] : string } = { }
161
+ const authBearer = this . auth . session ( ) ?. access_token ?? this . supabaseKey
157
162
headers [ 'apikey' ] = this . supabaseKey
158
163
headers [ 'Authorization' ] = `Bearer ${ authBearer } `
159
164
return headers
@@ -167,9 +172,7 @@ export default class SupabaseClient {
167
172
this . realtime . remove ( subscription )
168
173
return resolve ( true )
169
174
} )
170
- . receive ( 'error' , ( e : Error ) => {
171
- return reject ( e )
172
- } )
175
+ . receive ( 'error' , ( e : Error ) => reject ( e ) )
173
176
} )
174
177
}
175
178
}
0 commit comments