@@ -15,6 +15,7 @@ const db = firebase.database();
1515const signInBtn = document . getElementById ( "googleSignInBtn" ) ;
1616const userInfo = document . getElementById ( "user-info" ) ;
1717let currentUser = null ;
18+ let testEmailYet = false ;
1819
1920function isNumeric ( str ) {
2021 if ( typeof str != "string" ) return false // we only process strings!
@@ -58,41 +59,42 @@ auth.signInWithPopup(provider)
5859
5960 userInfo . innerText = `Signed in as ${ user . displayName } ` ;
6061 signInBtn . style . display = "none" ;
62+ afterSignIn ( user )
6163 } )
6264 . catch ( ( error ) => {
6365 console . error ( "Sign-in error:" , error ) ;
6466 alert ( "Sign-in failed." ) ;
6567 } ) ;
6668} ) ;
6769
68- auth . onAuthStateChanged ( async ( user ) => {
69- if ( user ) {
70- const uid = user . uid ;
71- const email = user . email ;
72- currentUser = user ;
73- userInfo . innerText = `Signed in as ${ user . displayName } ` ;
74- signInBtn . style . display = "none" ;
75-
76- if ( email === "[email protected] " ) { 77- document . getElementById ( "admin-panel" ) . style . display = "block" ;
78- loadReports ( ) ;
79- }
70+ async function afterSignIn ( user ) {
71+ if ( user ) {
72+ const uid = user . uid ;
73+ const email = user . email ;
74+ currentUser = user ;
75+ userInfo . innerText = `Signed in as ${ user . displayName } ` ;
76+ signInBtn . style . display = "none" ;
8077
81- loadLeaderboard ( ) ;
78+ if ( email === "[email protected] " ) { 79+ document . getElementById ( "admin-panel" ) . style . display = "block" ;
80+ loadReports ( ) ;
81+ }
8282
83- // Show current game
84- const snap = await db . ref ( "users/" + uid ) . once ( "value" ) ;
85- const userData = snap . val ( ) ;
86- if ( userData && userData . currentGameUrl ) {
87- const gameLink = document . getElementById ( "game-link" ) ;
88- gameLink . href = userData . currentGameUrl ;
89- gameLink . innerText = "Join Your Game" ;
90- document . getElementById ( "game-panel" ) . style . display = "block" ;
91- }
83+ loadLeaderboard ( ) ;
84+
85+ // Show current game
86+ const snap = await db . ref ( "users/" + uid ) . once ( "value" ) ;
87+ const userData = snap . val ( ) ;
88+ if ( userData && userData . currentGameUrl ) {
89+ const gameLink = document . getElementById ( "game-link" ) ;
90+ gameLink . href = userData . currentGameUrl ;
91+ gameLink . innerText = "Join Your Game" ;
92+ document . getElementById ( "game-panel" ) . style . display = "block" ;
93+ }
9294
93- loadMatches ( ) ;
95+ loadMatches ( ) ;
96+ }
9497}
95- } ) ;
9698
9799function loadLeaderboard ( ) {
98100db . ref ( "users" ) . once ( "value" ) . then ( snapshot => {
0 commit comments