Add reusable two-factor verification for login and money operations (#32)
This commit is contained in:
1 parent
b7a58b1a87
commit
fb40f860d2
41 files changed
+2439
-43
No files matched your search
@@ -23,6 +23,9 @@ class AuthFeedback extends StatelessWidget {
|
||||
AuthError.emailInUse => l.authEmailInUse,
|
||||
AuthError.unavailable => l.authUnavailable,
|
||||
AuthError.unexpected => l.authUnexpected,
|
||||
AuthError.factorLocked => l.factorLocked,
|
||||
AuthError.factorCooldown => l.factorWait,
|
||||
AuthError.factorRequired => l.factorRequired,
|
||||
};
|
||||
return Semantics(
|
||||
liveRegion: true,
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:sxchnge_analytics/sxchnge_analytics.dart';
|
||||
import 'package:sxchnge_auth/sxchnge_auth.dart';
|
||||
|
||||
import '../routing/routes.dart';
|
||||
import '../security/challenge.dart';
|
||||
import 'feedback.dart';
|
||||
import 'validation.dart';
|
||||
|
||||
@@ -96,11 +97,34 @@ class _AuthFormState extends State<AuthForm> {
|
||||
_confirmation.clear();
|
||||
context.goNamed(AppRoutes.verificationSent, extra: email);
|
||||
} else {
|
||||
await context.read<LoginProvider>().login(
|
||||
final login = context.read<LoginProvider>();
|
||||
await login.login(
|
||||
email: _email.text,
|
||||
password: _password.text,
|
||||
locale: locale,
|
||||
);
|
||||
if (!mounted || _signUp) return;
|
||||
final challenge = login.state.result?.challenge;
|
||||
if (challenge != null) {
|
||||
_password.clear();
|
||||
final grant = await verifyFactor(
|
||||
context,
|
||||
challenge: challenge,
|
||||
service: context.read<TwoFactorService>(),
|
||||
recorder: context.read<JourneyRecorder>(),
|
||||
journey: JourneyKind.login,
|
||||
);
|
||||
if (!mounted || _signUp) return;
|
||||
if (grant == null) {
|
||||
login.reset();
|
||||
context.read<JourneyRecorder>().abandon(JourneyExit.navigation);
|
||||
return;
|
||||
}
|
||||
await login.complete(challenge, grant);
|
||||
if (mounted && login.state.status == AuthStatus.success) {
|
||||
context.go('/accounts');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user