feat(auth): improve error handling for popup-blocked sign-in attempts
This commit is contained in:
parent
2063dffc09
commit
ff5c5f1b1d
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user