Users were experiencing sign-in failures when pop-ups were blocked by their browser, showing the error: "Sign-in failed. Please allow pop-ups for this site and try again."
Enhanced the Google authentication flow with automatic fallback from popup to redirect authentication:
- Primary Method: Attempts Google sign-in using popup (
signInWithPopup) - Automatic Fallback: If popup is blocked (
auth/popup-blockederror), automatically switches to redirect authentication (signInWithRedirect) - User Feedback: Shows toast notification when fallback occurs
- Added a small link below the Google sign-in button: "Having trouble with pop-ups? Try redirect sign-in"
- Allows users to directly use redirect authentication if they prefer
- Added
useEffectto handle authentication results when users return from Google's redirect - Maintains the same welcome email and user experience flow
-
Added imports:
import { signInWithRedirect, getRedirectResult, // ... existing imports } from 'firebase/auth';
-
Enhanced error handling:
if (err.code === 'auth/popup-blocked') { // Automatic fallback to redirect await signInWithRedirect(auth, googleProvider); }
-
Redirect result processing:
useEffect(() => { const handleRedirectResult = async () => { const result = await getRedirectResult(auth); // Handle successful redirect authentication }; handleRedirectResult(); }, []);
- Seamless: Users don't need to manually enable pop-ups or retry
- Informative: Clear feedback about what's happening
- Flexible: Both popup and redirect options available
- Consistent: Same welcome flow regardless of authentication method
- Popup Method: Works in most modern browsers when pop-ups are allowed
- Redirect Method: Universal compatibility, works even with strict popup blockers
- Automatic Detection: System automatically chooses the best method based on browser behavior
This enhancement ensures that authentication works reliably across all browsers and security settings while maintaining a smooth user experience.