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 {
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user