diff --git a/CHANGELOG.md b/CHANGELOG.md index 4767baf..4e00cc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ +## 1.1.7 + +- Fixed an issue with the `ArcaneAuthenticationService` where an exception would + be thrown when attempting to access an authentication token while no + `ArcaneAuthInterface` was registered. + ## 1.1.6 -- Updated logging feature to indicate the feature which was enabled or disabled within the log message, instead of only in the metadata +- Updated logging feature to indicate the feature which was enabled or disabled + within the log message, instead of only in the metadata. ## 1.1.5 @@ -12,15 +19,18 @@ ## 1.1.3 -- Arcane Auth no longer throws exceptions when log out fails, instead returning a `Result`. This behavior matches the login method. +- 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. +- Removed Flutter exception handling from `ArcaneLoggingService`, as this + functionality should be defined by a users' interface. ### Migration -Add the following to your `ArcaneLoggingInterface`'s `init` method to replicate the previous behavior: +Add the following to your `ArcaneLoggingInterface`'s `init` method to replicate +the previous behavior: ```dart // Handles unhandled Flutter errors by logging them. @@ -54,9 +64,10 @@ PlatformDispatcher.instance.onError = (error, stack) { ## 1.1.1 -- [BREAKING] Updated ArcaneAuthInterface to make the `resendVerificationCode`, `confirmSignup`, and `resetPassword` methods more versatile +- [BREAKING] Updated ArcaneAuthInterface to make the `resendVerificationCode`, + `confirmSignup`, and `resetPassword` methods more versatile -### Migration +Migration: | Class | Migration path | | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | @@ -66,9 +77,10 @@ PlatformDispatcher.instance.onError = (error, stack) { ## 1.1.0 -- [BREAKING] Updated the authentication service and interface to be more versatile +- [BREAKING] Updated the authentication service and interface to be more + versatile -### Migration +Migration: | Class | Migration path | | ------------------- | -------------------------------------------------------------------------------------- | @@ -85,7 +97,8 @@ PlatformDispatcher.instance.onError = (error, stack) { ## 1.0.6+1 -- Migrated linting rules to new [arcane_analysis](https://pub.dev/packages/arcane_analysis) package. +- Migrated linting rules to new + [arcane_analysis](https://pub.dev/packages/arcane_analysis) package. ## 1.0.6 @@ -97,18 +110,22 @@ PlatformDispatcher.instance.onError = (error, stack) { ## 1.0.5+1 -- Marked the `loginWithEmailAndPassword` method in ArcaneAuthenticationService as deprecated and updated example project +- Marked the `loginWithEmailAndPassword` method in `ArcaneAuthenticationService` + as deprecated and updated example project ## 1.0.5 -- Added the ability to use a generic type for the login method in ArcaneAuthenticationService -- Added the ability to reset the ArcaneAuthenticationService, which will unregister the current interface and clear the authentication state +- Added the ability to use a generic type for the login method in + ArcaneAuthenticationService +- Added the ability to reset the ArcaneAuthenticationService, which will + unregister the current interface and clear the authentication state - Removed unused testing tooling (e.g., `@visibleForTesting`) from the codebase - Migration guide: Remove usages of `setMocked` in your tests ## 1.0.4 -- Resolved an issue with authentication using the ArcaneAuthenticationService when logging in with an email and password +- Resolved an issue with authentication using the ArcaneAuthenticationService + when logging in with an email and password ## 1.0.3+1 @@ -116,11 +133,15 @@ PlatformDispatcher.instance.onError = (error, stack) { ## 1.0.3 -- Added the ability to switch back to the normal environment from the debug environment in ArcaneEnvironment -- (breaking) Made the optional `onLoggedOut` callback a Future instead of a void function in ArcaneAuthenticationService -- Added additional error handling to the login method in ArcaneAuthenticationService +- Added the ability to switch back to the normal environment from the debug + environment in ArcaneEnvironment +- (breaking) Made the optional `onLoggedOut` callback a Future instead of a void + function in ArcaneAuthenticationService +- Added additional error handling to the login method in + ArcaneAuthenticationService - Added support for following the system's theme in ArcaneTheme -- Removed the BuildContext parameter from the `switchTheme` method in ArcaneTheme +- Removed the BuildContext parameter from the `switchTheme` method in + ArcaneTheme ## 1.0.2 diff --git a/lib/src/services/authentication/authentication_service.dart b/lib/src/services/authentication/authentication_service.dart index 01b8768..1f30959 100644 --- a/lib/src/services/authentication/authentication_service.dart +++ b/lib/src/services/authentication/authentication_service.dart @@ -35,13 +35,7 @@ class ArcaneAuthenticationService extends ArcaneService { /// Provides direct access to the registered `ArcaneAuthInterface`, if one has /// been registered. - ArcaneAuthInterface get authInterface { - assert( - _authInterface != null, - "No ArcaneAuthInterface has been registered", - ); - return _authInterface!; - } + ArcaneAuthInterface? get authInterface => _authInterface; /// A shortcut to `status != AuthenticationStatus.unauthenticated`. bool get isAuthenticated => status != AuthenticationStatus.unauthenticated; @@ -53,12 +47,12 @@ class ArcaneAuthenticationService extends ArcaneService { /// provides one. This token is often used in the headers of HTTP requests /// to the backend API. Future get accessToken => - authInterface.accessToken ?? Future.value(""); + authInterface?.accessToken ?? Future.value(""); /// Returns a JWT refresh token if the registered `ArcaneAuthInterface` /// provides one. Future get refreshToken => - authInterface.refreshToken ?? Future.value(""); + authInterface?.refreshToken ?? Future.value(""); /// Removes any registered `ArcaneAuthInterface` and resets all values to /// default. @@ -158,14 +152,13 @@ class ArcaneAuthenticationService extends ArcaneService { Future> logOut({ Future Function()? onLoggedOut, }) async { + if (_authInterface == null) { + return Result.error("No ArcaneAuthInterface has been registered"); + } + if (!isAuthenticated) Result.error("User is not authenticated."); - assert( - _authInterface != null, - "No ArcaneAuthInterface has been registered", - ); - - final Result loggedOut = await authInterface.logout(); + final Result loggedOut = await authInterface!.logout(); if (loggedOut.isSuccess) { setUnauthenticated(); @@ -184,7 +177,7 @@ class ArcaneAuthenticationService extends ArcaneService { return Result.error("No ArcaneAuthInterface has been registered"); } - final Result result = await authInterface.login( + final Result result = await authInterface!.login( input: input, ); @@ -206,7 +199,7 @@ class ArcaneAuthenticationService extends ArcaneService { return Result.error("No ArcaneAuthInterface has been registered"); } - final Result? result = await authInterface.register( + final Result? result = await authInterface!.register( input: input, ); @@ -229,7 +222,7 @@ class ArcaneAuthenticationService extends ArcaneService { return Result.error("No ArcaneAuthInterface has been registered"); } - final Result? result = await authInterface.confirmSignup( + final Result? result = await authInterface!.confirmSignup( username: email, confirmationCode: confirmationCode, ); @@ -251,7 +244,7 @@ class ArcaneAuthenticationService extends ArcaneService { } final Future>? result = - authInterface.resendVerificationCode(input: email); + authInterface!.resendVerificationCode(input: email); if (result == null) { return Result.error( @@ -277,7 +270,7 @@ class ArcaneAuthenticationService extends ArcaneService { return Result.error("No ArcaneAuthInterface has been registered"); } - final Result? result = await authInterface.resetPassword( + final Result? result = await authInterface!.resetPassword( email: email, newPassword: newPassword, code: confirmationCode, diff --git a/pubspec.yaml b/pubspec.yaml index a9b36e1..4d33af8 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.6 +version: 1.1.7 repository: https://github.com/hanskokx/arcane_framework issue_tracker: https://github.com/hanskokx/arcane_framework/issues