diff --git a/lib/src/services/authentication/authentication_service.dart b/lib/src/services/authentication/authentication_service.dart index 9c253e1..b06dc7d 100644 --- a/lib/src/services/authentication/authentication_service.dart +++ b/lib/src/services/authentication/authentication_service.dart @@ -1,6 +1,7 @@ import "dart:async"; import "package:arcane_framework/arcane_framework.dart"; +import "package:flutter/foundation.dart"; import "package:flutter/widgets.dart"; import "package:flutter_bloc/flutter_bloc.dart"; @@ -37,11 +38,11 @@ class ArcaneAuthenticationService extends ArcaneService { /// been registered. ArcaneAuthInterface get authInterface => _authInterface; - /// A shortcut to `status == AuthenticationStatus.authenticated`. - bool get isAuthenticated => status == AuthenticationStatus.authenticated; + /// A shortcut to `status != AuthenticationStatus.unauthenticated`. + bool get isAuthenticated => status != AuthenticationStatus.unauthenticated; - /// A shortcut to the `isSignedIn` getter of the registered `ArcaneAuthInterface`. - Future get isSignedIn => authInterface.isSignedIn; + /// Expose the ValueListenable so other widgets can listen to changes. + ValueListenable get isSignedIn => ValueNotifier(isAuthenticated); /// Returns a JWT access token if the registered `ArcaneAuthInterface` /// provides one. This token is often used in the headers of HTTP requests @@ -103,16 +104,16 @@ class ArcaneAuthenticationService extends ArcaneService { /// Logs the current user out. Upon successful logout, `status` will be set to /// `AuthenticationStatus.unauthenticated`. - Future logOut({required VoidCallback onLoggedOut}) async { + Future logOut({VoidCallback? onLoggedOut}) async { if (_mocked) return; - if (status == AuthenticationStatus.unauthenticated) return; + if (!isAuthenticated) return; final Result loggedOut = await authInterface.logout(); await loggedOut.fold( onSuccess: (_) async { setUnauthenticated(); - onLoggedOut(); + if (onLoggedOut != null) onLoggedOut(); }, onError: (e) { throw Exception(e);