mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 02:19:08 +02:00
Fix authentication interface and service methods for logout and login.
This commit is contained in:
@@ -36,7 +36,11 @@ abstract class ArcaneAuthInterface {
|
|||||||
/// This method terminates the current session and removes any stored tokens.
|
/// This method terminates the current session and removes any stored tokens.
|
||||||
/// Returns a `Result` that either contains a `void` on success or an error
|
/// Returns a `Result` that either contains a `void` on success or an error
|
||||||
/// message.
|
/// message.
|
||||||
Future<Result<void, String>> logout();
|
/// Upon a successful logout, the `onLoggedOut` method will be called if it
|
||||||
|
/// has been provided.
|
||||||
|
Future<Result<void, String>> logout({
|
||||||
|
Future<void> Function()? onLoggedOut,
|
||||||
|
});
|
||||||
|
|
||||||
/// Logs the user in using an optional, generic `T` type of input.
|
/// Logs the user in using an optional, generic `T` type of input.
|
||||||
/// This login method is a generic method that can be used to login with any
|
/// This login method is a generic method that can be used to login with any
|
||||||
@@ -44,6 +48,8 @@ abstract class ArcaneAuthInterface {
|
|||||||
/// and password. Any type of input can be passed in, and it will be handled
|
/// and password. Any type of input can be passed in, and it will be handled
|
||||||
/// by the implementation of the method wihin the specific authentication
|
/// by the implementation of the method wihin the specific authentication
|
||||||
/// service.
|
/// service.
|
||||||
|
/// Upon a successful login, the `onLoggedIn` method will be called if it
|
||||||
|
/// has been provided.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```dart
|
/// ```dart
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ class ArcaneAuthenticationService extends ArcaneService {
|
|||||||
/// Returns a JWT access token if the registered `ArcaneAuthInterface`
|
/// Returns a JWT access token if the registered `ArcaneAuthInterface`
|
||||||
/// provides one. This token is often used in the headers of HTTP requests
|
/// provides one. This token is often used in the headers of HTTP requests
|
||||||
/// to the backend API.
|
/// to the backend API.
|
||||||
Future<String?> get accessToken =>
|
Future<String?> get accessToken async =>
|
||||||
authInterface?.accessToken ?? Future.value("");
|
await authInterface?.accessToken ?? Future.value("");
|
||||||
|
|
||||||
/// Returns a JWT refresh token if the registered `ArcaneAuthInterface`
|
/// Returns a JWT refresh token if the registered `ArcaneAuthInterface`
|
||||||
/// provides one.
|
/// provides one.
|
||||||
Future<String?> get refreshToken =>
|
Future<String?> get refreshToken async =>
|
||||||
authInterface?.refreshToken ?? Future.value("");
|
await authInterface?.refreshToken ?? Future.value("");
|
||||||
|
|
||||||
AuthenticationStatus? _previousModeWhenSettingDebug;
|
AuthenticationStatus? _previousModeWhenSettingDebug;
|
||||||
|
|
||||||
@@ -169,11 +169,12 @@ class ArcaneAuthenticationService extends ArcaneService {
|
|||||||
|
|
||||||
if (!isAuthenticated) Result.error("User is not authenticated.");
|
if (!isAuthenticated) Result.error("User is not authenticated.");
|
||||||
|
|
||||||
final Result<void, String> loggedOut = await authInterface!.logout();
|
final Result<void, String> loggedOut = await authInterface!.logout(
|
||||||
|
onLoggedOut: onLoggedOut,
|
||||||
|
);
|
||||||
|
|
||||||
if (loggedOut.isSuccess) {
|
if (loggedOut.isSuccess) {
|
||||||
setUnauthenticated();
|
setUnauthenticated();
|
||||||
if (onLoggedOut != null) await onLoggedOut();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_previousModeWhenSettingDebug = null;
|
_previousModeWhenSettingDebug = null;
|
||||||
@@ -192,11 +193,11 @@ class ArcaneAuthenticationService extends ArcaneService {
|
|||||||
|
|
||||||
final Result<void, String> result = await authInterface!.login(
|
final Result<void, String> result = await authInterface!.login(
|
||||||
input: input,
|
input: input,
|
||||||
|
onLoggedIn: onLoggedIn,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
setAuthenticated();
|
setAuthenticated();
|
||||||
if (onLoggedIn != null) await onLoggedIn();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user