Skip to content

Commit b0d8162

Browse files
committed
make sure auth isn't called internally when accessToken is used
1 parent 343c5e6 commit b0d8162

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/supabase/lib/src/supabase_client.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ class SupabaseClient {
9191
..clear()
9292
..addAll(_headers);
9393

94-
auth.headers
95-
..clear()
96-
..addAll({
97-
...Constants.defaultHeaders,
98-
..._getAuthHeaders(),
99-
...headers,
100-
});
94+
if (accessToken == null) {
95+
auth.headers
96+
..clear()
97+
..addAll({
98+
...Constants.defaultHeaders,
99+
..._getAuthHeaders(),
100+
...headers,
101+
});
102+
}
101103

102104
// To apply the new headers in the realtime client,
103105
// manually unsubscribe and resubscribe to all channels.
@@ -142,7 +144,7 @@ class SupabaseClient {
142144
functions = _initFunctionsClient();
143145
storage = _initStorageClient(storageOptions.retryAttempts);
144146
realtime = _initRealtimeClient(options: realtimeClientOptions);
145-
if (accessToken != null) {
147+
if (accessToken == null) {
146148
_listenForAuthEvents();
147149
}
148150
}

packages/supabase/test/client_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void main() {
192192
return 'jwt';
193193
});
194194
expect(
195-
supabase.auth.currentUser,
195+
() => supabase.auth.currentUser,
196196
throwsA(AuthException(
197197
'Supabase Client is configured with the accessToken option, accessing supabase.auth is not possible.')));
198198
});

0 commit comments

Comments
 (0)