blob: 5b6c7a1fb1281b64dcb5abd3bc9a14dadcd08b58 (
plain)
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
|
$(document).ready(function(){
function showAlert(message) {
// Get the snackbar DIV
var x = document.getElementById("snackbar");
$('#snackbar').text(message)
// Add the "show" class to DIV
x.className = "show";
// After 3 seconds, remove the show class from DIV
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
$('#login').click(function(){
var email = $("#email").val()
var password = $("#password").val()
if(email === '' || password === '') {
showAlert('Please fill in all the fields')
} else {
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
showAlert(errorMessage)
// ...
});
}
})
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
window.location.replace('../dashboard')
}
else {
showAlert("Failed to sign in. Try again.")
}
});
})
|