Skip to content

Commit af8e368

Browse files
authored
fix(realtime_client, supabase): pass apikey as the initial access token for realtime client (supabase#596)
* pass apikey as the initial access token for realtime client * ignore lint error for new AppLifecycleState
1 parent a349ae0 commit af8e368

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

packages/realtime_client/lib/src/realtime_client.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class RealtimeClient {
104104
eventsPerSecondLimitMs = (1000 / int.parse(eventsPerSecond)).floor();
105105
}
106106

107-
accessToken = this.headers['Authorization']?.split(' ').last;
107+
final customJWT = this.headers['Authorization']?.split(' ').last;
108+
accessToken = customJWT ?? params['apikey'];
108109

109110
this.reconnectAfterMs =
110111
reconnectAfterMs ?? RetryTimer.createRetryFunction();

packages/realtime_client/test/socket_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ void main() {
3939

4040
group('constructor', () {
4141
test('sets defaults', () async {
42-
final socket = RealtimeClient('wss://example.com/socket');
42+
final socket =
43+
RealtimeClient('wss://example.com/socket', params: {'apikey': '123'});
4344
expect(socket.channels.length, 0);
4445
expect(socket.sendBuffer.length, 0);
4546
expect(socket.ref, 0);
@@ -65,6 +66,7 @@ void main() {
6566
socket.headers['X-Client-Info']!.split('/').first,
6667
'realtime-dart',
6768
);
69+
expect(socket.accessToken, '123');
6870
});
6971

7072
test('overrides some defaults with options', () async {

packages/supabase/test/client_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ void main() {
5555
containsPair('log_level', 'info'),
5656
);
5757
});
58+
59+
test('realtime access token is set properly', () {
60+
expect(client.realtime.accessToken, supabaseKey);
61+
});
5862
});
5963

6064
group('auth', () {

packages/supabase_flutter/lib/src/supabase_auth.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class SupabaseAuth with WidgetsBindingObserver {
159159

160160
@override
161161
void didChangeAppLifecycleState(AppLifecycleState state) {
162+
// ignore:missing_enum_constant_in_switch
162163
switch (state) {
163164
case AppLifecycleState.resumed:
164165
_recoverSupabaseSession();

0 commit comments

Comments
 (0)