-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (33 loc) · 1.17 KB
/
app.js
File metadata and controls
40 lines (33 loc) · 1.17 KB
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
// app.js
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};
firebase.initializeApp(firebaseConfig);
const categorySelect = document.getElementById('category');
const githubAuthButton = document.getElementById('github-auth-button');
const githubAuthProvider = new firebase.auth.GithubAuthProvider();
githubAuthButton.addEventListener('click', () => {
firebase.auth().signInWithPopup(githubAuthProvider)
.then((result) => {
const user = result.user;
saveUserData(user.uid, {
category: categorySelect.value,
githubUsername: user.displayName,
email: user.email,
photoURL: user.photoURL,
});
alert('User signed in successfully!');
})
.catch((error) => {
console.error(error.message);
alert('Error signing in with GitHub');
});
});
function saveUserData(uid, data) {
firebase.database().ref('users/' + uid).set(data);
}