mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 02:19:08 +02:00
v1.1.1+1
- Updated README Signed-off-by: Hans Kokx <hans.kokx@hackberry.se>
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 1.1.1+1
|
||||||
|
|
||||||
|
- Updated example in README
|
||||||
|
|
||||||
## 1.1.1
|
## 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
|
||||||
|
|||||||
@@ -242,57 +242,42 @@ The Arcane Framework provides a useful interface for performing common authentic
|
|||||||
To get started, create an authentication interface provider and register it in the Arcane authentication module:
|
To get started, create an authentication interface provider and register it in the Arcane authentication module:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
typedef LoginInput = ({String email, String password});
|
import "package:arcane_framework/arcane_framework.dart";
|
||||||
|
|
||||||
// Create an authentication interface
|
typedef Credentials = ({String email, String password});
|
||||||
class AuthProviderInterface implements ArcaneAuthInterface {
|
|
||||||
AuthProviderInterface._internal();
|
|
||||||
|
|
||||||
static bool _mocked = false;
|
class DebugAuthInterface implements ArcaneAuthInterface {
|
||||||
|
DebugAuthInterface._internal();
|
||||||
|
|
||||||
static final AuthProviderInterface _instance = AuthProviderInterface._internal();
|
static final ArcaneAuthInterface _instance = DebugAuthInterface._internal();
|
||||||
static AuthProviderInterface get I => _instance;
|
static ArcaneAuthInterface get I => _instance;
|
||||||
|
|
||||||
Future<AuthSession?> get _session async {
|
|
||||||
return await ThirdPartyAuthProvider.fetchAuthSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> get isSignedIn =>
|
Future<bool> get isSignedIn => Future.value(_isSignedIn);
|
||||||
_session.then((value) => value?.isSignedIn == true);
|
bool _isSignedIn = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> get accessToken => isSignedIn.then(
|
Future<String?> get accessToken => isSignedIn.then(
|
||||||
(loggedIn) => loggedIn
|
(loggedIn) => loggedIn ? "access_token" : null,
|
||||||
? _session.then(
|
|
||||||
(value) => value?.accessToken,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> get refreshToken => isSignedIn.then(
|
Future<String?> get refreshToken => isSignedIn.then(
|
||||||
(loggedIn) => loggedIn
|
(loggedIn) => loggedIn ? "refresh_token" : null,
|
||||||
? _session.then(
|
|
||||||
(value) => value?.refreshToken,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<void, String>> logout() async {
|
Future<Result<void, String>> logout() async {
|
||||||
final result = await _session.signOut();
|
Arcane.log("Logging out");
|
||||||
|
|
||||||
if (result is FailedSignOut) {
|
_isSignedIn = false;
|
||||||
return Result.error(result.exception.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.ok(null);
|
return Result.ok(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<void, String>> login<LoginInput>({
|
Future<Result<void, String>> login<Credentials>({
|
||||||
LoginInput? input,
|
Credentials? input,
|
||||||
Future<void> Function()? onLoggedIn,
|
Future<void> Function()? onLoggedIn,
|
||||||
}) async {
|
}) async {
|
||||||
final bool alreadyLoggedIn = await isSignedIn;
|
final bool alreadyLoggedIn = await isSignedIn;
|
||||||
@@ -304,111 +289,67 @@ class AuthProviderInterface implements ArcaneAuthInterface {
|
|||||||
final String email = credentials.email;
|
final String email = credentials.email;
|
||||||
final String password = credentials.password;
|
final String password = credentials.password;
|
||||||
|
|
||||||
try {
|
Arcane.log("Logging in as $email using password $password");
|
||||||
final SignInResult result = await _session.signIn(
|
|
||||||
username: email,
|
_isSignedIn = true;
|
||||||
password: password,
|
|
||||||
);
|
return Result.ok(null);
|
||||||
return Result.ok(null);
|
|
||||||
} on AuthException catch (e) {
|
|
||||||
return Result.error("Error signing in: ${e.message}");
|
|
||||||
} catch (e) {
|
|
||||||
return Result.error("Error signing in: $e");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<String, String>> resendVerificationCode(String email) async {
|
Future<Result<String, String>> resendVerificationCode<T>({
|
||||||
try {
|
T? input,
|
||||||
final result = await _session.resendSignUpCode(username: email);
|
|
||||||
return Result.ok(result.message);
|
|
||||||
} catch (e) {
|
|
||||||
return Result.error("Error resending verification code: ${e.message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<Result<SignUpStep, String>> signup({
|
|
||||||
required String password,
|
|
||||||
required String email,
|
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
Arcane.log("Re-sending verification code to $input");
|
||||||
final SignUpResult result = await _session.signUp(
|
return Result.ok("Code sent");
|
||||||
username: email,
|
}
|
||||||
password: password,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result.nextStep.signUpStep == AuthSignUpStep.confirmSignUp) {
|
@override
|
||||||
return Result.ok(SignUpStep.confirmSignUp);
|
Future<Result<SignUpStep, String>> register<Credentials>({
|
||||||
}
|
Credentials? input,
|
||||||
|
}) async {
|
||||||
|
if (input != null) {
|
||||||
|
final credentials = input as ({String email, String password});
|
||||||
|
|
||||||
return Result.ok(SignUpStep.done);
|
final String email = credentials.email;
|
||||||
} catch (e) {
|
final String password = credentials.password;
|
||||||
return Result.error("Error signing up user: ${e.message}");
|
|
||||||
|
Arcane.log("Creating account for $email with password $password");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Result.ok(SignUpStep.confirmSignUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<bool, String>> confirmSignup({
|
Future<Result<bool, String>> confirmSignup({
|
||||||
required String username,
|
String? username,
|
||||||
required String confirmationCode,
|
String? confirmationCode,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
Arcane.log(
|
||||||
final SignUpResult result = await _session.confirmSignUp(
|
"Confirming registration for $username with code $confirmationCode",
|
||||||
username: username,
|
);
|
||||||
confirmationCode: confirmationCode,
|
return Result.ok(true);
|
||||||
);
|
|
||||||
|
|
||||||
return Result.ok(result.isSignUpComplete);
|
|
||||||
} on AuthException catch (e) {
|
|
||||||
return Result.error("Error confirming user: ${e.message}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<bool, String>> resetPassword({
|
Future<Result<bool, String>> resetPassword({
|
||||||
required String email,
|
String? email,
|
||||||
String? newPassword,
|
String? newPassword,
|
||||||
String? code,
|
String? code,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
Arcane.log("Resetting password for $email");
|
||||||
late ResetPasswordResult result;
|
return Result.ok(true);
|
||||||
if (newPassword != null && code != null) {
|
|
||||||
result = await _session.confirmResetPassword(
|
|
||||||
username: email,
|
|
||||||
newPassword: newPassword,
|
|
||||||
confirmationCode: code,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newPassword == null && code == null) {
|
|
||||||
result = await _session.resetPassword(
|
|
||||||
username: email,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.ok(result.isPasswordReset);
|
|
||||||
} catch (e) {
|
|
||||||
return Result.error("Error resetting the password: ${e.message}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
if (_mocked) return;
|
Arcane.log("Debug auth interface initialized.");
|
||||||
|
return;
|
||||||
if (ThirdPartyAuthProvider.isConfigured) return;
|
|
||||||
|
|
||||||
await ThirdPartyAuthProvider.initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@visibleForTesting
|
|
||||||
static void setMocked() {
|
|
||||||
_mocked = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Register an interface to handle user authentication.
|
// Register an interface to handle user authentication.
|
||||||
await Arcane.auth.registerInterface(AuthProviderInterface.I);
|
await Arcane.auth.registerInterface(AuthProviderInterface.I);
|
||||||
```
|
```
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name: arcane_framework
|
name: arcane_framework
|
||||||
description: "Agnostic Reusable Component Architecture for New Ecosystems: a modern framework for bootstrapping new applications"
|
description: "Agnostic Reusable Component Architecture for New Ecosystems: a modern framework for bootstrapping new applications"
|
||||||
version: 1.1.1
|
version: 1.1.1+1
|
||||||
repository: https://github.com/hanskokx/arcane_framework
|
repository: https://github.com/hanskokx/arcane_framework
|
||||||
issue_tracker: https://github.com/hanskokx/arcane_framework/issues
|
issue_tracker: https://github.com/hanskokx/arcane_framework/issues
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user