fixed guardian login edge cases and misleading placeholders on failed loads

This commit is contained in:
2026-09-20 19:03:45 +02:00
parent 2423c1a75e
commit 630497abdd
23 changed files with 299 additions and 72 deletions
+43 -8
View File
@@ -54,9 +54,14 @@ class GuardianLoginController extends ChangeNotifier {
String? get errorMessage => _errorMessage;
String? get errorDetails => _errorDetails;
bool canResend() {
bool canResend() => resendCooldown() == Duration.zero;
/// Restzeit, bis [resend] wieder erlaubt ist.
Duration resendCooldown() {
final pending = _pending;
return pending != null && !_now().isBefore(pending.resendAvailableAt);
if (pending == null) return Duration.zero;
final remaining = pending.resendAvailableAt.difference(_now());
return remaining.isNegative ? Duration.zero : remaining;
}
/// Picks up a request started before the app was closed.
@@ -77,8 +82,12 @@ class GuardianLoginController extends ChangeNotifier {
Future<bool> requestCode(String email) async {
final normalized = email.trim().toLowerCase();
if (DemoMode.matchesGuardian(normalized)) {
await _signIn(GuardianSession(email: normalized, isDemo: true));
return true;
var signedIn = false;
await _run(() async {
await _signIn(GuardianSession(email: normalized, isDemo: true));
signedIn = true;
});
return signedIn;
}
await _run(() async {
final secret = DeviceBinding.generateSecret();
@@ -128,6 +137,17 @@ class GuardianLoginController extends ChangeNotifier {
return _complete(linkToken: link.linkToken);
}
/// A mail link that does not belong to the server the app talks to (a live
/// link while the app points at beta). Without this the tap would do nothing
/// at all.
void rejectForeignLink() {
_errorMessage =
'Dieser Anmeldelink gehört zu einem anderen Server als dem, mit dem '
'die App gerade verbunden ist. Bitte gib den Code aus der E-Mail ein.';
_errorDetails = null;
notifyListeners();
}
/// Abandons the running request, e.g. to correct a mistyped address.
Future<void> changeEmail() async {
await _store.clear();
@@ -140,7 +160,15 @@ class GuardianLoginController extends ChangeNotifier {
Future<bool> _complete({String? code, String? linkToken}) async {
final pending = _pending;
if (pending == null) return false;
if (pending == null) {
_errorMessage = GuardianLoginException.messageFor(
GuardianLoginError.requestExpired,
);
_errorDetails = null;
_step = GuardianLoginStep.enterEmail;
notifyListeners();
return false;
}
var signedIn = false;
await _run(() async {
await _verify.run(
@@ -188,9 +216,16 @@ class GuardianLoginController extends ChangeNotifier {
}
static Future<void> _defaultSignIn(Session session) async {
// Drop any widget snapshot of a previous account before the new one loads.
await WidgetSync.clear();
await WidgetSync.triggerUpdate();
// Sign in first: the one-time code is already spent at this point, so a
// failing widget reset must not cost the session (the user would have to
// request a fresh mail for a login that actually succeeded).
await SessionManager().signIn(session);
// Drop any widget snapshot of a previous account.
try {
await WidgetSync.clear();
await WidgetSync.triggerUpdate();
} on Object catch (e) {
log('Guardian login: widget reset failed: $e');
}
}
}