-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
75 lines (62 loc) · 2.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>H4H Firebase Workshop</title>
</head>
<body>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-analytics.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyBjrhACq73QCRfmvUcXVYM5E5L9IxxaQvE",
authDomain: "h4h-2024-24d68.firebaseapp.com",
projectId: "h4h-2024-24d68",
storageBucket: "h4h-2024-24d68.appspot.com",
messagingSenderId: "966050860028",
appId: "1:966050860028:web:035c8c014cbb9efcf6c079",
measurementId: "G-DYKV8FLTNB"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
</script>
<h1>Welcome to the Firebase Workshop</h1>
<p>Click the button below to sign in with Google</p>
<button id="google-signin">Sign in with Google</button>
<div id="user-data"></div>
<div>
<h2>Database Data</h2>
<button id="read-data-button">Read Data from Firestore</button>
<p id="data"></p>
</div>
<script type="module">
import { getAuth, GoogleAuthProvider, signInWithPopup, signOut } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-auth.js"
import { getFirestore, doc, getDoc } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-firestore.js"
const googleSignInButton = document.getElementById("google-signin");
const readDataButton = document.getElementById("read-data-button");
const auth = getAuth();
const provider = new GoogleAuthProvider();
googleSignInButton.addEventListener("click", signInWithGoogle);
readDataButton.addEventListener("click", readData);
function signInWithGoogle() {
signInWithPopup(auth, provider).then((result) => {
const user = result.user;
document.getElementById("user-data").innerText = user.uid;
})
}
function readData() {
const reference = doc(getFirestore(), "test", "myDocument");
getDoc(reference).then( (doc) => {
document.getElementById("data").innerText = JSON.stringify(doc.data());
});
}
</script>
</body>
</html>