feat(auth): improve error handling for popup-blocked sign-in attempts

This commit is contained in:
Nik Afiq 2025-12-11 22:22:40 +09:00
parent 2063dffc09
commit ff5c5f1b1d

View File

@ -78,17 +78,12 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
try { try {
await signInWithPopup(auth, provider); await signInWithPopup(auth, provider);
} catch (err: any) { } catch (err: any) {
// Avoid redirect fallback to prevent navigation/404; surface a clearer popup-blocked message.
const code = err?.code ?? ""; const code = err?.code ?? "";
// Common cases where redirect works better if (code === "auth/popup-blocked") {
const redirectable = [ setError("ポップアップがブロックされました。ブラウザで許可してください。");
"auth/popup-blocked", console.error("signin popup blocked:", err);
"auth/operation-not-supported-in-this-environment", return;
"auth/unauthorized-domain",
];
if (redirectable.includes(code)) {
const { signInWithRedirect } = await import("firebase/auth");
await signInWithRedirect(auth, provider);
return; // navigation will happen
} }
const msg = err instanceof Error ? err.message : String(err); const msg = err instanceof Error ? err.message : String(err);
setError(msg); // keep the message for the UI setError(msg); // keep the message for the UI