mirror of
https://github.com/hanskokx/arcane_implementations.git
synced 2026-05-14 02:19:05 +02:00
Updated auth interface example
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -3,6 +3,8 @@ import "package:amplify_flutter/amplify_flutter.dart";
|
|||||||
import "package:arcane_framework/arcane_framework.dart";
|
import "package:arcane_framework/arcane_framework.dart";
|
||||||
import "package:flutter/widgets.dart";
|
import "package:flutter/widgets.dart";
|
||||||
|
|
||||||
|
typedef LoginInput = ({String email, String password});
|
||||||
|
|
||||||
class AmplifyInterface implements ArcaneAuthInterface {
|
class AmplifyInterface implements ArcaneAuthInterface {
|
||||||
AmplifyInterface._internal();
|
AmplifyInterface._internal();
|
||||||
|
|
||||||
@@ -56,20 +58,19 @@ class AmplifyInterface implements ArcaneAuthInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<void, String>> login<T>({
|
Future<Result<void, String>> login<LoginInput>({
|
||||||
T? input,
|
LoginInput? input,
|
||||||
Future<void> Function()? onLoggedIn,
|
Future<void> Function()? onLoggedIn,
|
||||||
}) =>
|
|
||||||
throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<Result<void, String>> loginWithEmailAndPassword({
|
|
||||||
required String email,
|
|
||||||
required String password,
|
|
||||||
}) async {
|
}) async {
|
||||||
final bool alreadyLoggedIn = await isSignedIn;
|
final bool alreadyLoggedIn = await isSignedIn;
|
||||||
|
|
||||||
if (alreadyLoggedIn) return Result.ok(null);
|
if (alreadyLoggedIn) return Result.ok(null);
|
||||||
|
if (input == null) return Result.error("No input provided");
|
||||||
|
|
||||||
|
final credentials = input as ({String email, String password});
|
||||||
|
|
||||||
|
final String email = credentials.email;
|
||||||
|
final String password = credentials.password;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final CognitoSignInResult result = await _cognito.signIn(
|
final CognitoSignInResult result = await _cognito.signIn(
|
||||||
@@ -84,6 +85,13 @@ class AmplifyInterface implements ArcaneAuthInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Result<void, String>> loginWithEmailAndPassword({
|
||||||
|
required String email,
|
||||||
|
required String password,
|
||||||
|
}) async =>
|
||||||
|
throw UnimplementedError();
|
||||||
|
|
||||||
Future<Result<void, String>> _handleSignInResult(
|
Future<Result<void, String>> _handleSignInResult(
|
||||||
SignInResult result,
|
SignInResult result,
|
||||||
String email,
|
String email,
|
||||||
|
|||||||
Reference in New Issue
Block a user