forked from beRajeevKumar/Frontend_Mentor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.html
89 lines (67 loc) · 3.04 KB
/
login.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="signUp.css" />
<title>Sign In</title>
</head>
<body>
<form id="signinForm">
<div class="container">
<h1>Sign In</h1>
<hr>
<div class="form">
<label for="email"><b>Email</b></label>
<input type="email" placeholder="Enter Email" autocomplete="email" id="email" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" autocomplete="new-password" id="psw" required>
<div class="buttons">
<button type="button" class="cancelbtn">Cancel</button>
<button type="submit" class="signinbtn">Sign In</button>
</div>
</div>
</div>
</form>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.14.0/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.14.0/firebase-analytics.js";
import { getFirestore, addDoc, collection,getDoc } from "https://www.gstatic.com/firebasejs/10.14.0/firebase-firestore.js"; // Correct import for Firestore
import { getAuth, createUserWithEmailAndPassword ,signInWithEmailAndPassword} from "https://www.gstatic.com/firebasejs/10.14.0/firebase-auth.js";
const firebaseConfig = {
apiKey: "AIzaSyC7ihLRIl47Iu6nk6qh_Ak8i3pSYw3tO4A",
authDomain: "frontend-mentor-cceee.firebaseapp.com",
projectId: "frontend-mentor-cceee",
storageBucket: "frontend-mentor-cceee.appspot.com",
messagingSenderId: "51303965383",
appId: "1:51303965383:web:2f8c20fb952bd844dd94e2",
measurementId: "G-S2BV64K72R",
databaseURL: "https://frontend-mentor-cceee-default-rtdb.firebaseio.com"
};
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db = getFirestore(app);
const auth = getAuth();
const form = document.getElementById('signinForm');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('psw').value;
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
const user = userCredential.user;
const uid=user.uid;
console.log(user);
const displayName = user.displayName ? user.displayName : "User";
alert("Welcome, " + displayName);
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
console.log(errorCode, errorMessage);
});
})
</script>
</body>
</html>