-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandleUserAuth.js
More file actions
41 lines (31 loc) · 1.38 KB
/
handleUserAuth.js
File metadata and controls
41 lines (31 loc) · 1.38 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
41
import { auth } from "./firebaseConfig.js";
import { signInUserWithGoogle } from "./utilities/authentication/SignInWithGoogle.js";
// Listener triggers every time there is a change in the users sign-in state
auth.onAuthStateChanged(function (user) {
// if the user is signed in
if (user) {
console.log("User is logged in:", user.displayName);
// Redirect the user to todo.html page
window.location.href = "todo.html";
// if the user is signed out
} else {
console.log("User is not logged in");
}
});
// Function calls signInUserWithGoogle and error checks to see if user has successfully signed in
async function handleGoogleSignUp(){
//calls function signInUserWithGoogle and receives a response
const response = await signInUserWithGoogle();
// if an error occurs duing the sign-in process
if (response === "error") {
console.log("Error, user not signed in with Google");
// if the user has successfully signed in
} else {
console.log("success, user has signed in with Google");
}
};
// obtaining the button located in 'index.html' through the id 'button'
const signInBtn = document.getElementById("button");
// Listener that will trigger when the signin button is clicked
// Once Button is clicked function handleGoogleSignUp is called
signInBtn.addEventListener("click", handleGoogleSignUp);