safari fix

This commit is contained in:
2026-04-21 11:49:48 +05:30
parent cfd24de69d
commit 6ea06d2d3b
3 changed files with 51 additions and 5 deletions

View File

@@ -191,11 +191,12 @@ export function AuthProvider({ children }: { children: ReactNode }) {
}
useEffect(() => {
// Handle returning from a redirect sign-in (mobile flow)
// Handle returning from a redirect sign-in (Safari / iOS / Android WebViews)
getRedirectResult(auth).catch((error) => {
console.error('[Auth] Redirect sign-in error:', error)
setAuthError(error instanceof Error ? error.message : 'Sign-in failed')
})
// onAuthStateChanged below handles the successful redirect result automatically
const unsubscribe = onAuthStateChanged(auth, async (u) => {
setUser(u)
@@ -218,6 +219,14 @@ export function AuthProvider({ children }: { children: ReactNode }) {
async function signInWithGoogle() {
setAuthError(null)
await setPersistence(auth, browserLocalPersistence)
// Safari blocks cross-origin storage in popups (ITP), so use redirect flow
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
if (isSafari) {
await signInWithRedirect(auth, googleProvider)
return
}
try {
await signInWithPopup(auth, googleProvider)
} catch (err: unknown) {