Skip to content

Commit

Permalink
fix: add dispose to auth client
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Aug 15, 2024
1 parent e372c46 commit 4b400f0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/gotrue/lib/src/broadcast_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ BroadcastChannel getBroadcastChannel(String broadcastKey) {
return (
onMessage: broadcast.onMessage.map((event) => event.data.toString()),
postMessage: broadcast.postMessage,
close: broadcast.close,
);
}
8 changes: 8 additions & 0 deletions packages/gotrue/lib/src/gotrue_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,14 @@ class GoTrueClient {
}
}

void dispose() {
_onAuthStateChangeController.close();
_onAuthStateChangeControllerSync.close();
_broadcastChannel?.close();
_refreshTokenCompleter?.completeError(AuthException('Disposed'));
_autoRefreshTicker?.cancel();
}

/// Generates a new JWT.
///
/// To prevent multiple simultaneous requests it catches an already ongoing request by using the global [_refreshTokenCompleter].
Expand Down
1 change: 1 addition & 0 deletions packages/gotrue/lib/src/types/types.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
typedef BroadcastChannel = ({
Stream<String> onMessage,
void Function(String) postMessage,
void Function() close,
});

enum AuthFlowType {
Expand Down
1 change: 1 addition & 0 deletions packages/supabase/lib/src/supabase_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class SupabaseClient {
Future<void> dispose() async {
await _authStateSubscription?.cancel();
await _isolate.dispose();
auth.dispose();
}

GoTrueClient _initSupabaseAuthClient({
Expand Down

0 comments on commit 4b400f0

Please sign in to comment.