Skip to content

Commit 24c9098

Browse files
Update app.js
1 parent c225ab0 commit 24c9098

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ auth.signInWithPopup(provider)
4141
}
4242
}
4343

44+
// Only create the user record if it doesn't exist
4445
const uid = user.uid;
4546
const userRef = db.ref("users/" + uid);
46-
47-
// Only create the user record if it doesn't exist
47+
4848
userRef.once("value").then((snapshot) => {
4949
if (!snapshot.exists()) {
5050
userRef.set({
@@ -53,7 +53,11 @@ auth.signInWithPopup(provider)
5353
score: 0,
5454
opponent: null,
5555
currentGameUrl: null
56+
}).then(() => {
57+
loadLeaderboard(); // Only call it after user is added
5658
});
59+
} else {
60+
loadLeaderboard(); // Call immediately if already exists
5761
}
5862
});
5963

@@ -80,8 +84,6 @@ async function afterSignIn(user) {
8084
loadReports();
8185
}
8286

83-
loadLeaderboard();
84-
8587
// Show current game
8688
const snap = await db.ref("users/" + uid).once("value");
8789
const userData = snap.val();

0 commit comments

Comments
 (0)