From 606404b4d3bd7a1cf3b59789d2fd922a7e1e3a0d Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Fri, 25 Oct 2024 12:17:10 +0200 Subject: [PATCH] v1.1.3 - Auth logout no longer throws exceptions, preferring a Result return value instead. Signed-off-by: Hans Kokx --- CHANGELOG.md | 4 ++++ .../authentication_service.dart | 21 +++++++++---------- pubspec.yaml | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6c736e..d2777a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.3 + +- Arcane Auth no longer throws exceptions when log out fails, instead returning a `Result`. This behavior matches the login method. + ## 1.1.2 - Removed Flutter exception handling from `ArcaneLoggingService`, as this functionality should be defined by a users' interface. diff --git a/lib/src/services/authentication/authentication_service.dart b/lib/src/services/authentication/authentication_service.dart index 73f626c..01b8768 100644 --- a/lib/src/services/authentication/authentication_service.dart +++ b/lib/src/services/authentication/authentication_service.dart @@ -155,8 +155,10 @@ class ArcaneAuthenticationService extends ArcaneService { /// Logs the current user out. Upon successful logout, `status` will be set to /// `AuthenticationStatus.unauthenticated`. - Future logOut({Future Function()? onLoggedOut}) async { - if (!isAuthenticated) return; + Future> logOut({ + Future Function()? onLoggedOut, + }) async { + if (!isAuthenticated) Result.error("User is not authenticated."); assert( _authInterface != null, @@ -165,15 +167,12 @@ class ArcaneAuthenticationService extends ArcaneService { final Result loggedOut = await authInterface.logout(); - await loggedOut.fold( - onSuccess: (_) async { - setUnauthenticated(); - if (onLoggedOut != null) await onLoggedOut(); - }, - onError: (e) { - throw Exception(e); - }, - ); + if (loggedOut.isSuccess) { + setUnauthenticated(); + if (onLoggedOut != null) await onLoggedOut(); + } + + return loggedOut; } /// Logs the user in using an optional, generic `T` type of input. diff --git a/pubspec.yaml b/pubspec.yaml index 5ac536b..0f028c5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: arcane_framework description: "Agnostic Reusable Component Architecture for New Ecosystems: a modern framework for bootstrapping new applications" -version: 1.1.2 +version: 1.1.3 repository: https://github.com/hanskokx/arcane_framework issue_tracker: https://github.com/hanskokx/arcane_framework/issues