safari fix
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user