1
0
forked from baron/baron-sso

모바일 승인 완료 화면에서 verify_failed 오류 노출 개선

This commit is contained in:
ai-cell-a100-1
2026-05-19 17:40:27 +09:00
parent 5376baf6d8
commit 7ad1743758
8 changed files with 1053 additions and 1624 deletions

View File

@@ -722,6 +722,14 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
return false;
}
bool _isAlreadyVerifiedError(Object e) {
final msg = e.toString().toLowerCase();
return msg.contains('already_used') ||
msg.contains('already_verified') ||
msg.contains('session_active') ||
msg.contains('verify_failed');
}
void _markVerificationApproved(
String message, {
String? title,
@@ -730,13 +738,19 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
String actionPath = '/',
bool autoRedirect = false,
Duration redirectDelay = const Duration(seconds: 2),
bool isRemote = false,
}) {
if (!mounted) return;
final resolvedTitle = title ?? tr('ui.userfront.login.verification.title');
final resolvedTitle = title ??
(isRemote
? tr('ui.userfront.login.verification.title_remote')
: tr('ui.userfront.login.verification.title'));
final resolvedPageTitle =
pageTitle ?? tr('ui.userfront.login.verification.page_title');
final resolvedActionLabel =
actionLabel ?? tr('ui.userfront.login.verification.action_label');
final resolvedActionLabel = actionLabel ??
(isRemote
? tr('ui.userfront.login.verification.action_label_close')
: tr('ui.userfront.login.verification.action_label'));
setState(() {
_verificationApproved = true;
_verificationMessage = message;
@@ -744,6 +758,10 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
_verificationPageTitle = resolvedPageTitle;
_verificationActionLabel = resolvedActionLabel;
});
if (isRemote) {
_verificationRedirectTimer?.cancel();
return;
}
_verificationRedirectTimer?.cancel();
if (autoRedirect) {
_verificationRedirectTimer = Timer(redirectDelay, () {
@@ -785,6 +803,11 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
const SizedBox(height: 24),
FilledButton(
onPressed: () {
if (_verificationActionLabel ==
tr('ui.userfront.login.verification.action_label_close')) {
webWindow.close();
return;
}
final hasLocalSession =
(AuthTokenStore.getToken()?.isNotEmpty ?? false) ||
AuthTokenStore.usesCookie();
@@ -813,6 +836,9 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
final localSessionMessage = tr(
'msg.userfront.login.verification.approved_local',
);
final remoteApprovedMessage =
tr('msg.userfront.login.verification.approved_remote');
try {
// Use Backend to verify the token (Backend-Driven Flow)
final res = await AuthProxyService.verifyMagicLink(
@@ -829,7 +855,11 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
if (status == 'approved' || (jwt == null && _verificationOnly)) {
if (mounted) {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
if (_verificationOnly && !hasLocalSession) {
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
} else {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
}
}
return;
}
@@ -847,15 +877,23 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
}
if (mounted) {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
if (_verificationOnly && !hasLocalSession) {
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
} else {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
}
}
} catch (e) {
debugPrint("[Auth] Verification FAILED for token: $token. Error: $e");
if (mounted) {
if (_verificationOnly && _isAlreadyVerifiedError(e)) {
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
return;
}
_showError(
tr(
'msg.userfront.login.verification_failed',
params: {'error': e.toString()},
params: {'error': e.toString().replaceFirst('Exception: ', '')},
),
);
}
@@ -875,6 +913,9 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
final localSessionMessage = tr(
'msg.userfront.login.verification.approved_local',
);
final remoteApprovedMessage =
tr('msg.userfront.login.verification.approved_remote');
try {
final res = await AuthProxyService.verifyLoginCode(
sanitizedLoginId,
@@ -894,7 +935,11 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
if (jwt == null && status == 'approved') {
if (mounted) {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
if (_verificationOnly && !hasLocalSession) {
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
} else {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
}
}
return;
}
@@ -908,7 +953,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
return;
}
if (_verificationOnly) {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
return;
}
_onLoginSuccess(jwt, provider: res['provider'] as String?);
@@ -916,17 +961,25 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
}
if (_verificationOnly && mounted) {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
if (!hasLocalSession) {
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
} else {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
}
}
} catch (e) {
debugPrint(
"[Auth] Code verification FAILED for loginId: $sanitizedLoginId. Error: $e",
);
if (mounted) {
if (_verificationOnly && _isAlreadyVerifiedError(e)) {
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
return;
}
_showError(
tr(
'msg.userfront.login.verification_failed',
params: {'error': e.toString()},
params: {'error': e.toString().replaceFirst('Exception: ', '')},
),
);
}
@@ -941,6 +994,9 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
final localSessionMessage = tr(
'msg.userfront.login.verification.approved_local',
);
final remoteApprovedMessage =
tr('msg.userfront.login.verification.approved_remote');
try {
final res = await AuthProxyService.verifyLoginShortCode(
sanitized,
@@ -956,7 +1012,11 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
if (jwt == null && status == 'approved') {
if (mounted) {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
if (_verificationOnly && !hasLocalSession) {
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
} else {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
}
}
return;
}
@@ -970,7 +1030,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
return;
}
if (_verificationOnly) {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
return;
}
_onLoginSuccess(jwt, provider: res['provider'] as String?);
@@ -978,15 +1038,23 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
}
if (_verificationOnly && mounted) {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
if (!hasLocalSession) {
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
} else {
_markVerificationApproved(approvedMessage, actionPath: actionPath);
}
}
} catch (e) {
debugPrint("[Auth] Short code verification FAILED. Error: $e");
if (mounted) {
if (_verificationOnly && _isAlreadyVerifiedError(e)) {
_markVerificationApproved(remoteApprovedMessage, isRemote: true);
return;
}
_showError(
tr(
'msg.userfront.login.verification_failed',
params: {'error': e.toString()},
params: {'error': e.toString().replaceFirst('Exception: ', '')},
),
);
}