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