-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
120 lines (85 loc) · 2.77 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function run(){
window.open('https://youtu.be/mYt7NwunB7o')
}
const autha = firebase.auth()
const db =firebase.firestore()
const content=document.querySelector("#content");
function abc(){
window.location.href="main.html"
}
autha.onAuthStateChanged(user=>{
if(user){
content.innerHTML=`
<button id ="abc" onclick="abc()">USE THE APP</button>
<button id="logout">Logout</button>`;
//logout
const logout = document.querySelector("#logout");
logout.addEventListener('click', (event) => {
event.preventDefault();
autha.signOut().then(cred=>{
//console.log(cred);
});
});
}else{
content.innerHTML=`
<form id="signup-form">
<input type="email" id="signup-email" placeholder="Email"/>
<input type="password" id="signup-password" placeholder="Password"/>
<button>Sign Up</button>
</form>
<hr>
<form id="login-form">
<input type="email" id="login-email" placeholder="Email" required/>
<input type="password" id="login-password" placeholder="Password" required/>
<button>Log In </button>
</form>
<button id="google">Sign in with google</button>
<button id="fb">Sign in with facebook</button>
`;
//signup using email
const signup =document.querySelector("#signup-form");
signup.addEventListener('submit',(event)=>{
event.preventDefault();
const email =signup['signup-email'].value;
const password =signup['signup-password'].value;
autha.createUserWithEmailAndPassword(email,password).then(cred=>{
//console.log(cred);
signup.reset();
}).catch(event=>{
alert(event.message);
});
});
//login with email
const login=document.querySelector("#login-form");
login.addEventListener('submit',(event)=>{
event.preventDefault();
const email =login['login-email'].value;
const password =login['login-password'].value;
autha.signInWithEmailAndPassword(email,password).then(cred=>{
//console.log(cred);
login.reset();
}).catch(event=>{
alert(event.message);
});
});
//Sign in with Facebook
const facebook =document.querySelector("#fb");
facebook.addEventListener('click' , event => {
event.preventDefault();
let provider = new firebase.auth.FacebookAuthProvider();
auth.signInWithPopup(provider).then( cred =>{
alert('logged in with Facebook');
}).catch(e=>{
alert(e.message);
});
});
//sign in with google
const google= document.querySelector('#google');
google.addEventListener('click', (e) => {
let provider = new firebase.auth.GoogleAuthProvider();
auth.signInWithPopup(provider).then(cred =>{
console.log(cred.user);
});
});
}
});