@@ -24,51 +24,51 @@ function isNumeric(str) {
2424} // from https://stackoverflow.com/a/175787
2525
2626signInBtn . addEventListener ( "click" , ( ) => {
27- const provider = new firebase . auth . GoogleAuthProvider ( ) ;
28- auth . signInWithPopup ( provider )
29- . then ( ( result ) => {
30- const testing = true ;
31-
32- const user = result . user ;
33- const email = user . email ;
34-
35- console . log ( email ) ;
36- if ( testing === false ) {
37- if ( ! email . endsWith ( "@student.sbhs.nsw.edu.au" ) || ! isNumeric ( email [ 0 ] ) ) {
38- alert ( "Please use your @student.sbhs.nsw.edu.au account to prevent double accounts." ) ;
39- auth . signOut ( ) ;
40- return ;
27+ const provider = new firebase . auth . GoogleAuthProvider ( ) ;
28+ auth . signInWithPopup ( provider )
29+ . then ( ( result ) => {
30+ const testing = true ;
31+
32+ const user = result . user ;
33+ const email = user . email ;
34+
35+ console . log ( email ) ;
36+ if ( testing === false ) {
37+ if ( ! email . endsWith ( "@student.sbhs.nsw.edu.au" ) || ! isNumeric ( email [ 0 ] ) ) {
38+ alert ( "Please use your [studentID]@student.sbhs.nsw.edu.au account to help prevent double accounts." ) ;
39+ auth . signOut ( ) ;
40+ return ;
41+ }
4142 }
42- }
4343
44- // Only create the user record if it doesn't exist
45- const uid = user . uid ;
46- const userRef = db . ref ( "users/" + uid ) ;
47-
48- userRef . once ( "value" ) . then ( ( snapshot ) => {
49- if ( ! snapshot . exists ( ) ) {
50- userRef . set ( {
51- name : user . displayName ,
52- email : user . email ,
53- score : 0 ,
54- opponent : null ,
55- currentGameUrl : null
56- } ) . then ( ( ) => {
57- loadLeaderboard ( ) ; // Only call it after user is added
58- } ) ;
59- } else {
60- loadLeaderboard ( ) ; // Call immediately if already exists
61- }
44+ // Only create the user record if it doesn't exist
45+ const uid = user . uid ;
46+ const userRef = db . ref ( "users/" + uid ) ;
47+
48+ userRef . once ( "value" ) . then ( ( snapshot ) => {
49+ if ( ! snapshot . exists ( ) ) {
50+ userRef . set ( {
51+ name : user . displayName ,
52+ email : user . email ,
53+ score : 0 ,
54+ opponent : null ,
55+ currentGameUrl : null
56+ } ) . then ( ( ) => {
57+ loadLeaderboard ( ) ; // Only call it after user is added
58+ } ) ;
59+ } else {
60+ loadLeaderboard ( ) ; // Call immediately if already exists
61+ }
62+ } ) ;
63+
64+ userInfo . innerText = `Signed in as ${ user . displayName } ` ;
65+ signInBtn . style . display = "none" ;
66+ afterSignIn ( user )
67+ } )
68+ . catch ( ( error ) => {
69+ console . error ( "Sign-in error:" , error ) ;
70+ alert ( "Sign-in failed." ) ;
6271 } ) ;
63-
64- userInfo . innerText = `Signed in as ${ user . displayName } ` ;
65- signInBtn . style . display = "none" ;
66- afterSignIn ( user )
67- } )
68- . catch ( ( error ) => {
69- console . error ( "Sign-in error:" , error ) ;
70- alert ( "Sign-in failed." ) ;
71- } ) ;
7272} ) ;
7373
7474auth . onAuthStateChanged ( ( user ) => {
0 commit comments