소셜 웹 로그인 중단·실패를 이메일 오류 대신 소셜 로그인 문구로 안내 · 네트워크 오류 안내 · Android 중단된 웹 로그인 정리 후 재시도
This commit is contained in:
@@ -78,7 +78,7 @@ final class FirebaseAccountLinker implements AccountLinker {
|
||||
} on fb.FirebaseAuthException catch (error) {
|
||||
if (isWebFlowCancelled(error)) return const AuthCancelled();
|
||||
return AuthFailed(
|
||||
authCatalogCode(error),
|
||||
authCatalogCode(error, flow: AuthFlow.link),
|
||||
authMessage(error, flow: AuthFlow.link),
|
||||
);
|
||||
} on Object catch (error) {
|
||||
@@ -108,7 +108,7 @@ final class FirebaseAccountLinker implements AccountLinker {
|
||||
return AuthSucceeded(_accountOf(_firebaseAuth.currentUser, provider));
|
||||
} on fb.FirebaseAuthException catch (error) {
|
||||
return AuthFailed(
|
||||
authCatalogCode(error),
|
||||
authCatalogCode(error, flow: AuthFlow.link),
|
||||
authMessage(error, flow: AuthFlow.link),
|
||||
);
|
||||
}
|
||||
@@ -116,8 +116,8 @@ final class FirebaseAccountLinker implements AccountLinker {
|
||||
|
||||
/// LINE(OIDC) 연결 — 웹 흐름이 인증과 연결을 한 번에 끝낸다. 검증 · 충돌 거부는 Firebase 가 한다.
|
||||
Future<AuthOutcome> _linkOidc(fb.User user, OidcSignInProvider impl) async {
|
||||
final result = await untilAbandoned(
|
||||
user.linkWithProvider(impl.authProvider),
|
||||
final result = await retryStaleWebContext(
|
||||
() => untilAbandoned(user.linkWithProvider(impl.authProvider)),
|
||||
);
|
||||
return AuthSucceeded(_accountOf(result.user, impl.provider));
|
||||
}
|
||||
|
||||
@@ -369,9 +369,11 @@ const _names = {
|
||||
AuthProviderKind.email: '이메일로',
|
||||
};
|
||||
|
||||
/// 로그인 결과 안내. 취소 · 중단도 안내한다 — 로그인 성공으로 처리하지 않고 다시 시도하게 한다.
|
||||
/// 아무 말 없이 화면이 그대로면 사용자는 앱이 멈춘 줄 안다.
|
||||
String? authNotice(AuthOutcome outcome) => switch (outcome) {
|
||||
AuthSucceeded() => null,
|
||||
AuthCancelled() => null,
|
||||
AuthCancelled() => '로그인이 완료되지 않았습니다. 다시 시도해 주세요.',
|
||||
AuthFailed(:final code, :final message) => '[$code] $message',
|
||||
AuthNotConfigured(:final provider, :final missing) =>
|
||||
'${provider.shortName} 로그인은 아직 준비 중입니다.\n'
|
||||
|
||||
@@ -90,7 +90,7 @@ final class GoogleSignInProvider
|
||||
return AuthFailed('E-AUTH-03', error.description ?? error.code.name);
|
||||
} on fb.FirebaseAuthException catch (error) {
|
||||
return AuthFailed(
|
||||
authCatalogCode(error),
|
||||
authCatalogCode(error, flow: AuthFlow.signIn),
|
||||
authMessage(error, flow: AuthFlow.signIn),
|
||||
);
|
||||
}
|
||||
@@ -188,7 +188,7 @@ final class AppleSignInProvider
|
||||
return const AuthFailed('E-AUTH-03', '소셜 로그인에 실패했습니다.');
|
||||
} on fb.FirebaseAuthException catch (error) {
|
||||
return AuthFailed(
|
||||
authCatalogCode(error),
|
||||
authCatalogCode(error, flow: AuthFlow.signIn),
|
||||
authMessage(error, flow: AuthFlow.signIn),
|
||||
);
|
||||
}
|
||||
@@ -271,16 +271,18 @@ final class OidcSignInProvider implements SocialAuthProvider {
|
||||
final missing = missingConfig;
|
||||
if (missing.isNotEmpty) return AuthNotConfigured(provider, missing);
|
||||
try {
|
||||
final result = await untilAbandoned(
|
||||
(firebaseAuth ?? fb.FirebaseAuth.instance).signInWithProvider(
|
||||
authProvider,
|
||||
final result = await retryStaleWebContext(
|
||||
() => untilAbandoned(
|
||||
(firebaseAuth ?? fb.FirebaseAuth.instance).signInWithProvider(
|
||||
authProvider,
|
||||
),
|
||||
),
|
||||
);
|
||||
return AuthSucceeded(_toAccount(result.user, provider));
|
||||
} on fb.FirebaseAuthException catch (error) {
|
||||
if (isWebFlowCancelled(error)) return const AuthCancelled();
|
||||
return AuthFailed(
|
||||
authCatalogCode(error),
|
||||
authCatalogCode(error, flow: AuthFlow.signIn),
|
||||
authMessage(error, flow: AuthFlow.signIn),
|
||||
);
|
||||
}
|
||||
@@ -417,7 +419,10 @@ final class KakaoSignInProvider implements SocialAuthProvider {
|
||||
_ => flow == AuthFlow.link ? '계정 연결에 실패했습니다.' : '소셜 로그인에 실패했습니다.',
|
||||
});
|
||||
} on fb.FirebaseAuthException catch (error) {
|
||||
return AuthFailed(authCatalogCode(error), authMessage(error, flow: flow));
|
||||
return AuthFailed(
|
||||
authCatalogCode(error, flow: flow),
|
||||
authMessage(error, flow: flow),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,9 +440,39 @@ final class KakaoSignInProvider implements SocialAuthProvider {
|
||||
}
|
||||
|
||||
/// 사용자가 인가 웹 화면을 닫았다. Android 는 `canceled`, iOS 는 `cancelled` 철자다.
|
||||
/// `user-cancelled` 는 동의 화면에서 거절한 경우다(웹 흐름).
|
||||
bool isWebFlowCancelled(fb.FirebaseAuthException error) =>
|
||||
error.code == 'web-context-canceled' ||
|
||||
error.code == 'web-context-cancelled';
|
||||
error.code == 'web-context-cancelled' ||
|
||||
error.code == 'user-cancelled';
|
||||
|
||||
const _authChannel = MethodChannel('kr.co.fanuzu.app/auth');
|
||||
|
||||
/// Android — 결과 없이 남은 Firebase 웹 인가 대기 작업을 취소로 끝낸다(MainActivity `cancelPendingWebSignIn`).
|
||||
///
|
||||
/// LINE 로그인 도중 본인 확인을 하러 LINE 앱으로 갔다 돌아오는 식으로 흐름이 끊기면, Firebase 는 대기 작업을
|
||||
/// 들고 있어 다음 시도를 `web-context-already-presented` 로 막는다(다시 눌러도 로그인이 안 됨).
|
||||
/// 대기 작업이 없으면 아무 일도 하지 않는다. iOS · 웹은 SDK 가 스스로 정리한다.
|
||||
Future<void> clearStaleWebSignIn() async {
|
||||
if (kIsWeb || defaultTargetPlatform != TargetPlatform.android) return;
|
||||
try {
|
||||
await _authChannel.invokeMethod<void>('cancelPendingWebSignIn');
|
||||
} on Object catch (error) {
|
||||
debugPrint('[Auth] clear stale web sign-in skipped: $error');
|
||||
}
|
||||
}
|
||||
|
||||
/// 웹 인가가 앞선 흐름에 막혔으면(`web-context-already-presented`) 남은 대기를 정리하고 **한 번만** 다시 연다.
|
||||
/// 취소 · 실패 뒤에도 정상적으로 다시 시도할 수 있어야 한다.
|
||||
Future<T> retryStaleWebContext<T>(Future<T> Function() attempt) async {
|
||||
try {
|
||||
return await attempt();
|
||||
} on fb.FirebaseAuthException catch (error) {
|
||||
if (error.code != 'web-context-already-presented') rethrow;
|
||||
await clearStaleWebSignIn();
|
||||
return attempt();
|
||||
}
|
||||
}
|
||||
|
||||
/// Android 에서 웹 인가 흐름이 결과 없이 버려졌으면 취소(`web-context-canceled`)로 끝낸다.
|
||||
///
|
||||
@@ -462,6 +497,8 @@ Future<T> untilAbandoned<T>(
|
||||
if (state != AppLifecycleState.resumed) return;
|
||||
timer = Timer(grace, () {
|
||||
if (done.isCompleted) return;
|
||||
// Firebase 쪽 대기 작업도 끝낸다 — 남기면 다음 시도가 web-context-already-presented 로 막힌다.
|
||||
unawaited(clearStaleWebSignIn());
|
||||
done.completeError(
|
||||
fb.FirebaseAuthException(code: 'web-context-canceled'),
|
||||
);
|
||||
@@ -550,8 +587,8 @@ final class EmailPasswordProvider implements EmailAuthProvider {
|
||||
return const AuthCancelled();
|
||||
} on fb.FirebaseAuthException catch (error) {
|
||||
return AuthFailed(
|
||||
authCatalogCode(error),
|
||||
authMessage(error, flow: AuthFlow.signIn),
|
||||
authCatalogCode(error, flow: AuthFlow.email),
|
||||
authMessage(error, flow: AuthFlow.email),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -564,8 +601,8 @@ final class EmailPasswordProvider implements EmailAuthProvider {
|
||||
return AuthSucceeded(_toAccount(result.user, provider));
|
||||
} on fb.FirebaseAuthException catch (error) {
|
||||
return AuthFailed(
|
||||
authCatalogCode(error),
|
||||
authMessage(error, flow: AuthFlow.signIn),
|
||||
authCatalogCode(error, flow: AuthFlow.email),
|
||||
authMessage(error, flow: AuthFlow.email),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -580,7 +617,14 @@ final class EmailPasswordProvider implements EmailAuthProvider {
|
||||
///
|
||||
/// **계정 존재 여부를 드러내지 않는다.** 「등록되지 않은 이메일」과 「비밀번호
|
||||
/// 오류」를 갈라 주면 어느 이메일이 가입돼 있는지 훑을 수 있다.
|
||||
String authCatalogCode(fb.FirebaseAuthException error) => switch (error.code) {
|
||||
///
|
||||
/// 알 수 없는 코드는 경로별로 갈린다 — 이메일 폼([AuthFlow.email])은 E-AUTH-01, 소셜 로그인 · 연결은
|
||||
/// 소셜 실패 E-AUTH-03 이다. 하나로 E-AUTH-01 이면 LINE 웹 로그인이 끊길 때(`web-*`)
|
||||
/// 「이메일 또는 비밀번호를 확인해 주세요」가 뜬다.
|
||||
String authCatalogCode(
|
||||
fb.FirebaseAuthException error, {
|
||||
required AuthFlow flow,
|
||||
}) => switch (error.code) {
|
||||
'email-already-in-use' => 'E-AUTH-04',
|
||||
'weak-password' => 'E-AUTH-05',
|
||||
'invalid-email' => 'E-AUTH-06',
|
||||
@@ -600,7 +644,7 @@ String authCatalogCode(fb.FirebaseAuthException error) => switch (error.code) {
|
||||
'invalid-user-token' ||
|
||||
'user-mismatch' ||
|
||||
'user-disabled' => 'E-AUTH-12',
|
||||
_ => 'E-AUTH-01',
|
||||
_ => flow == AuthFlow.email ? 'E-AUTH-01' : 'E-AUTH-03',
|
||||
};
|
||||
|
||||
/// 오류 문구가 갈리는 경로.
|
||||
@@ -609,9 +653,12 @@ String authCatalogCode(fb.FirebaseAuthException error) => switch (error.code) {
|
||||
/// 밝힌다. 기본값을 두지 않는 것은 의도한 것이다 — 새 호출부가 경로를 밝히지
|
||||
/// 않고 지나가면 다시 한쪽 문구가 양쪽에 나간다.
|
||||
enum AuthFlow {
|
||||
/// 로그인 화면에서 계정으로 들어가려는 경로(`signInWithCredential`).
|
||||
/// 소셜 로그인 경로(`signInWithCredential` · `signInWithProvider`).
|
||||
signIn,
|
||||
|
||||
/// 이메일 · 비밀번호 폼(QA 내부 경로). 알 수 없는 실패를 「이메일 또는 비밀번호」로 안내하는 유일한 경로다.
|
||||
email,
|
||||
|
||||
/// 이미 로그인한 UID 에 소셜 제공자를 붙이거나 떼는 경로
|
||||
/// (`linkWithCredential` · `unlink`) — 별첨 B v1.4.
|
||||
link,
|
||||
@@ -631,7 +678,8 @@ String authMessage(fb.FirebaseAuthException error, {required AuthFlow flow}) =>
|
||||
'invalid-email' => '이메일 형식이 올바르지 않습니다.',
|
||||
'too-many-requests' => '잠시 후 다시 시도해 주세요.',
|
||||
'account-exists-with-different-credential' => switch (flow) {
|
||||
AuthFlow.signIn => _otherProviderSignInGuide(error.email),
|
||||
AuthFlow.signIn || AuthFlow.email =>
|
||||
_otherProviderSignInGuide(error.email),
|
||||
AuthFlow.link => '다른 FANUZU 계정에 이미 연결된 소셜 계정입니다.',
|
||||
},
|
||||
// 붙이려는 자격증명이 남의 UID 에 이미 달려 있다. 연결 경로에서만 난다.
|
||||
@@ -644,7 +692,15 @@ String authMessage(fb.FirebaseAuthException error, {required AuthFlow flow}) =>
|
||||
'invalid-user-token' ||
|
||||
'user-mismatch' ||
|
||||
'user-disabled' => '보안을 위해 다시 로그인한 뒤 시도해 주세요.',
|
||||
_ => '이메일 또는 비밀번호를 확인해 주세요.',
|
||||
// 웹 인가 흐름이 끊기거나 망이 끊겼다 — 소셜 경로의 사실대로 알리고 다시 시도하게 한다.
|
||||
'web-context-already-presented' => '로그인이 완료되지 않았습니다. 다시 시도해 주세요.',
|
||||
'web-network-request-failed' ||
|
||||
'network-request-failed' => '네트워크 연결을 확인한 뒤 다시 시도해 주세요.',
|
||||
_ => switch (flow) {
|
||||
AuthFlow.email => '이메일 또는 비밀번호를 확인해 주세요.',
|
||||
AuthFlow.signIn => '소셜 로그인에 실패했습니다.',
|
||||
AuthFlow.link => '계정 연결에 실패했습니다.',
|
||||
},
|
||||
};
|
||||
|
||||
/// 「먼저 쓰던 수단으로 로그인한 뒤 SNS 연동에서 붙이라」는 안내.
|
||||
|
||||
Reference in New Issue
Block a user