Fix auth loop with initialization guard
This commit is contained in:
1 parent
f4dcfda334
commit
39ee33761b
1 file changed
+5
@@ -730,8 +730,11 @@ function getFriendDisplayName(uid) {
|
|||||||
return nick || displayName;
|
return nick || displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let _initializingUser = false;
|
||||||
|
|
||||||
// AUTH
|
// AUTH
|
||||||
onAuthStateChanged(auth, async (user) => {
|
onAuthStateChanged(auth, async (user) => {
|
||||||
|
if (_initializingUser) return;
|
||||||
if (isSignInWithEmailLink(auth, window.location.href)) {
|
if (isSignInWithEmailLink(auth, window.location.href)) {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const email = urlParams.get('email') || localStorage.getItem('emailForSignIn');
|
const email = urlParams.get('email') || localStorage.getItem('emailForSignIn');
|
||||||
@@ -774,6 +777,7 @@ window.confirmEmailSignIn = async function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function initUser(user) {
|
async function initUser(user) {
|
||||||
|
_initializingUser = true;
|
||||||
currentUser = user;
|
currentUser = user;
|
||||||
const userRef = doc(db, 'users', user.uid);
|
const userRef = doc(db, 'users', user.uid);
|
||||||
const snap = await getDoc(userRef);
|
const snap = await getDoc(userRef);
|
||||||
@@ -1306,6 +1310,7 @@ window.signInWithGoogle = async function() {
|
|||||||
try {
|
try {
|
||||||
const provider = new GoogleAuthProvider();
|
const provider = new GoogleAuthProvider();
|
||||||
const result = await signInWithPopup(auth, provider);
|
const result = await signInWithPopup(auth, provider);
|
||||||
|
_initializingUser = true;
|
||||||
await initUser(result.user);
|
await initUser(result.user);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
|
|||||||
Reference in new issue
Block a user