From 4b400f0686297ea2656dec41f1b8d2174af3c042 Mon Sep 17 00:00:00 2001 From: Vinzent Date: Thu, 15 Aug 2024 17:36:10 +0200 Subject: [PATCH] fix: add dispose to auth client --- packages/gotrue/lib/src/broadcast_web.dart | 1 + packages/gotrue/lib/src/gotrue_client.dart | 8 ++++++++ packages/gotrue/lib/src/types/types.dart | 1 + packages/supabase/lib/src/supabase_client.dart | 1 + 4 files changed, 11 insertions(+) diff --git a/packages/gotrue/lib/src/broadcast_web.dart b/packages/gotrue/lib/src/broadcast_web.dart index 9c96c4aa..8d3dae4f 100644 --- a/packages/gotrue/lib/src/broadcast_web.dart +++ b/packages/gotrue/lib/src/broadcast_web.dart @@ -7,5 +7,6 @@ BroadcastChannel getBroadcastChannel(String broadcastKey) { return ( onMessage: broadcast.onMessage.map((event) => event.data.toString()), postMessage: broadcast.postMessage, + close: broadcast.close, ); } diff --git a/packages/gotrue/lib/src/gotrue_client.dart b/packages/gotrue/lib/src/gotrue_client.dart index c39b3f01..6fc3efa7 100644 --- a/packages/gotrue/lib/src/gotrue_client.dart +++ b/packages/gotrue/lib/src/gotrue_client.dart @@ -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]. diff --git a/packages/gotrue/lib/src/types/types.dart b/packages/gotrue/lib/src/types/types.dart index 8a5e9f5c..cf142559 100644 --- a/packages/gotrue/lib/src/types/types.dart +++ b/packages/gotrue/lib/src/types/types.dart @@ -1,6 +1,7 @@ typedef BroadcastChannel = ({ Stream onMessage, void Function(String) postMessage, + void Function() close, }); enum AuthFlowType { diff --git a/packages/supabase/lib/src/supabase_client.dart b/packages/supabase/lib/src/supabase_client.dart index 3c5a9c63..4323a7ea 100644 --- a/packages/supabase/lib/src/supabase_client.dart +++ b/packages/supabase/lib/src/supabase_client.dart @@ -250,6 +250,7 @@ class SupabaseClient { Future dispose() async { await _authStateSubscription?.cancel(); await _isolate.dispose(); + auth.dispose(); } GoTrueClient _initSupabaseAuthClient({