-
-
Save azamsharp/380f9d13558a1ff8a66f6465f85326da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sign up | |
let emailTextBox = document.getElementById("emailTextBox") | |
let passwordTextBox = document.getElementById("passwordTextBox") | |
let btnSignUp = document.getElementById("btnSignUp") | |
// login | |
let loginEmailTextBox = document.getElementById("loginEmailTextBox") | |
let loginPasswordTextBox = document.getElementById("loginPasswordTextBox") | |
let btnLogin = document.getElementById("btnLogin") | |
// signout | |
let btnSignOut = document.getElementById("btnSignOut") | |
btnSignOut.addEventListener('click',function(){ | |
firebase.auth().signOut() | |
}) | |
// when the user auth status changed | |
firebase.auth().onAuthStateChanged(function(user){ | |
if(user) { | |
console.log("onAuthStateChanged") | |
//window.location = "my-tasks.html" | |
} | |
}) | |
// sign in user | |
btnLogin.addEventListener('click',function(){ | |
let email = loginEmailTextBox.value | |
let password = loginPasswordTextBox.value | |
firebase.auth().signInWithEmailAndPassword(email,password) | |
.then(function(response){ | |
let user = response.user | |
if(user) { | |
// go to a different page | |
// home page | |
// window.location = "my-tasks.html" | |
} | |
console.log(response) | |
// get the current user | |
// let currentUser = firebase.auth().currentUser | |
// currentUser.uid // unique identifier for the user | |
}).catch(function(error){ | |
console.log(error) | |
}) | |
}) | |
// creates a new user | |
btnSignUp.addEventListener('click',function(){ | |
let email = emailTextBox.value | |
let password = passwordTextBox.value | |
firebase.auth().createUserWithEmailAndPassword(email,password) | |
.then(function(response){ | |
console.log(response) | |
}).catch(function(error){ | |
console.log(error) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment