Skip to content

Commit 7f603bb

Browse files
Create Auth.js
Signed-off-by: Abdurhaman Mohammed Ahamed <abdurhamanmohammeda@gmail.com>
1 parent b42dca3 commit 7f603bb

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Js/Auth.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const firebaseConfig = {
2+
apiKey:"YOUR_KEY",
3+
authDomain:"YOUR_DOMAIN",
4+
projectId:"YOUR_ID"
5+
};
6+
7+
firebase.initializeApp(firebaseConfig);
8+
9+
const auth = firebase.auth();
10+
const db = firebase.firestore();
11+
12+
function login(){
13+
14+
const e=document.getElementById("email").value;
15+
const p=document.getElementById("password").value;
16+
17+
auth.signInWithEmailAndPassword(e,p)
18+
.catch(err=>{
19+
document.getElementById("authMsg").innerText=err.message;
20+
});
21+
22+
}
23+
24+
function logout(){
25+
auth.signOut();
26+
}
27+
28+
auth.onAuthStateChanged(user=>{
29+
30+
if(user){
31+
32+
document.getElementById("loginSection").style.display="none";
33+
document.getElementById("mainApp").style.display="block";
34+
35+
}else{
36+
37+
document.getElementById("loginSection").style.display="block";
38+
document.getElementById("mainApp").style.display="none";
39+
40+
}
41+
42+
});

0 commit comments

Comments
 (0)