diff --git a/frontend/src/auth/AuthProvider.tsx b/frontend/src/auth/AuthProvider.tsx index a059203..a244155 100644 --- a/frontend/src/auth/AuthProvider.tsx +++ b/frontend/src/auth/AuthProvider.tsx @@ -77,16 +77,23 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { const provider = new GoogleAuthProvider(); try { await signInWithPopup(auth, provider); - } catch (err: unknown) { - // Fallback to redirect when popups are blocked. - const code = (err as { code?: string }).code || ""; - if (code === "auth/popup-blocked" || code === "auth/operation-not-supported-in-this-environment") { - await import("firebase/auth").then(({ signInWithRedirect }) => signInWithRedirect(auth, provider)); - } else { - const msg = err instanceof Error ? err.message : "Sign-in failed"; - setError(msg); - throw err; + } catch (err: any) { + 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 } + const msg = err instanceof Error ? err.message : String(err); + setError(msg); // keep the message for the UI + console.error("signin error:", err); + throw err; // let the caller catch if needed } } finally { setSigningIn(false); diff --git a/frontend/src/components/AuthStatus.tsx b/frontend/src/components/AuthStatus.tsx index 7c8212d..1a0a100 100644 --- a/frontend/src/components/AuthStatus.tsx +++ b/frontend/src/components/AuthStatus.tsx @@ -11,10 +11,13 @@ export default function AuthStatus() { } if (!user) { return ( - +