Skip to content

Commit 1a26631

Browse files
added main html and js
1 parent 3c9f9d8 commit 1a26631

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

app.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// app.js
2+
3+
// Replace these config values with your Firebase project settings
4+
const firebaseConfig = {
5+
apiKey: "YOUR_API_KEY",
6+
authDomain: "YOUR_PROJECT.firebaseapp.com",
7+
databaseURL: "https://YOUR_PROJECT.firebaseio.com",
8+
projectId: "YOUR_PROJECT_ID",
9+
storageBucket: "YOUR_PROJECT.appspot.com",
10+
messagingSenderId: "YOUR_SENDER_ID",
11+
appId: "YOUR_APP_ID"
12+
};
13+
14+
firebase.initializeApp(firebaseConfig);
15+
const auth = firebase.auth();
16+
const db = firebase.database();
17+
18+
const signInBtn = document.getElementById("googleSignInBtn");
19+
const userInfo = document.getElementById("user-info");
20+
21+
signInBtn.addEventListener("click", () => {
22+
const provider = new firebase.auth.GoogleAuthProvider();
23+
auth.signInWithPopup(provider)
24+
.then((result) => {
25+
const user = result.user;
26+
const email = user.email;
27+
28+
if (!email.endsWith("@myschool.nsw.edu.au")) {
29+
alert("Please use your school Google account.");
30+
auth.signOut();
31+
return;
32+
}
33+
34+
// Add user to database
35+
const uid = user.uid;
36+
db.ref("users/" + uid).set({
37+
name: user.displayName,
38+
email: user.email,
39+
score: 0
40+
});
41+
42+
userInfo.innerText = `Signed in as ${user.displayName}`;
43+
signInBtn.style.display = "none";
44+
})
45+
.catch((error) => {
46+
console.error("Sign-in error:", error);
47+
alert("Sign-in failed.");
48+
});
49+
});
50+

index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- index.html -->
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>Year 8 Chess Tournament</title>
6+
<meta charset="UTF-8">
7+
<script src="https://www.gstatic.com/firebasejs/9.22.2/firebase-app-compat.js"></script>
8+
<script src="https://www.gstatic.com/firebasejs/9.22.2/firebase-auth-compat.js"></script>
9+
<script src="https://www.gstatic.com/firebasejs/9.22.2/firebase-database-compat.js"></script>
10+
<script defer src="app.js"></script>
11+
</head>
12+
<body>
13+
<h1>Welcome to the Year 8 Chess Tournament</h1>
14+
<div id="user-section">
15+
<button id="googleSignInBtn">Sign in with Google</button>
16+
<p id="user-info"></p>
17+
</div>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)