-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
47 lines (34 loc) · 1.1 KB
/
form.js
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
const auth = firebase.auth();
//this function register users to the app and send data to firebase
function signup()
{
var email = document.getElementById("#email");
var password = document.getElementById("#password");
const promise = auth.createUserWithEmailAndPassword(email.value, password.value);
promise.catch(e => alert(e.message));
alert("signed up");
};
//this function let users log in to the app
function login(){
var email = document.getElementById("email");
var password = document.getElementById("password");
const promise = auth.signInWithEmailAndPassword(email.value, password.value);
promise.catch(e => alert(e.message));
alert("signed in");
}
function logOut(){
auth.logOut();
alert("logged Out");
}
//this function monitor the state of user and performs the respective task
auth.onAuthStateChanged(function(user){
if(user){
var user = firebase.auth().currentUser;
var name, email;
name = user.displayName;
email = user.email;
$("#emailadd").text(email)
}else{
//no user is signed in
}
});