Skip to content

Commit

Permalink
fix: properly handle exception on supabase-client for realtime set auth
Browse files Browse the repository at this point in the history
  • Loading branch information
dshukertjr committed Dec 12, 2024
1 parent 8045727 commit 7e660c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/realtime_client/lib/src/realtime_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ class RealtimeClient {
null,
Level.FINE,
);
throw 'InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed['exp']}';
throw FormatException(
'InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed['exp']}');
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion packages/supabase/lib/src/supabase_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,17 @@ class SupabaseClient {
// ignore: invalid_use_of_internal_member
_authStateSubscription = auth.onAuthStateChangeSync.listen(
(data) {
_handleTokenChanged(data.event, data.session?.accessToken);
try {
_handleTokenChanged(data.event, data.session?.accessToken);
} on FormatException catch (e) {
if (e.message.contains('InvalidJWTToken')) {
// The exception is thrown by RealtimeClient when the token is
// expired for example on app launch after the app has been closed
// for a while.
} else {
rethrow;
}
}
},
onError: (error, stack) {},
);
Expand Down

0 comments on commit 7e660c3

Please sign in to comment.