Fix Google redirect result handling on iOS

This commit is contained in:
Sterling Archer
2026-06-25 11:06:25 -07:00
parent 2eeb8285b9
commit 418184651a
+18 -11
View File
@@ -269,11 +269,11 @@
<div class="auth-card" id="auth-card">
<h2>Welcome</h2>
<p>Sign in or create an account to get started.</p>
<button class="btn btn-google" id="google-signin-btn" onclick="signInWithGoogle()">
<button class="btn btn-google" id="google-signin-btn" onclick="signInWithGoogle()" style="display:none">
<svg width="18" height="18" viewBox="0 0 18 18" style="flex-shrink:0"><path fill="#4285F4" d="M17.64 9.2c0-.637-.057-1.251-.164-1.84H9v3.481h4.844c-.209 1.125-.843 2.078-1.796 2.717v2.258h2.908c1.702-1.567 2.684-3.875 2.684-6.615z"/><path fill="#34A853" d="M9 18c2.43 0 4.467-.806 5.956-2.184l-2.908-2.258c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.584-5.036-3.711H.957v2.332C2.438 15.983 5.482 18 9 18z"/><path fill="#FBBC05" d="M3.964 10.707c-.18-.54-.282-1.117-.282-1.707s.102-1.167.282-1.707V4.961H.957C.347 6.175 0 7.55 0 9s.348 2.825.957 4.039l3.007-2.332z"/><path fill="#EA4335" d="M9 3.58c1.321 0 2.508.454 3.44 1.345l2.582-2.58C13.463.891 11.426 0 9 0 5.482 0 2.438 2.017.957 4.961L3.964 7.293C4.672 5.166 6.656 3.58 9 3.58z"/></svg>
Sign in with Google
</button>
<div style="display:flex;align-items:center;gap:12px;margin:16px 0">
<div id="google-divider" style="display:none;align-items:center;gap:12px;margin:16px 0">
<div style="flex:1;height:1px;background:var(--border)"></div>
<span style="font-size:12px;color:var(--muted)">or</span>
<div style="flex:1;height:1px;background:var(--border)"></div>
@@ -649,6 +649,12 @@ const fbApp = initializeApp(FIREBASE_CONFIG);
const auth = getAuth(fbApp);
const db = getFirestore(fbApp);
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
if (!isIOS) {
document.getElementById('google-signin-btn').style.display = 'flex';
document.getElementById('google-divider').style.display = 'flex';
}
let currentUser = null;
let currentUserData = null;
let currentProfileData = null;
@@ -725,16 +731,17 @@ function getFriendDisplayName(uid) {
}
// AUTH
onAuthStateChanged(auth, async (user) => {
try {
const redirectResult = await getRedirectResult(auth);
if (redirectResult?.user) {
await initUser(redirectResult.user);
return;
}
} catch(e) {
console.warn('Redirect result error:', e.code);
let _handlingRedirect = false;
getRedirectResult(auth).then(async (result) => {
if (result?.user) {
_handlingRedirect = true;
await initUser(result.user);
}
}).catch(e => console.warn('Redirect result error:', e.code));
onAuthStateChanged(auth, async (user) => {
if (_handlingRedirect) return;
if (isSignInWithEmailLink(auth, window.location.href)) {
const urlParams = new URLSearchParams(window.location.search);