File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments