-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 1.42 KB
/
index.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
import { auth } from './firebase.js';
import { signInWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/10.12.4/firebase-auth.js";
document.addEventListener('DOMContentLoaded', () => {
const loginForm = document.getElementById('loginForm');
const redirect = document.getElementById('Redirect');
loginForm.addEventListener('submit', (event) => {
event.preventDefault();
const email = loginForm.querySelector('input[type="text"]').value;
const password = loginForm.querySelector('input[type="password"]').value;
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
console.log("User signed in:", user);
alert("Successfully signed in!");
// Here you can redirect the user or update the UI
window.location.href = 'welcome.html';
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
console.error("Sign in error:", errorCode, errorMessage);
alert("Error signing in: " + errorMessage);
});
});
redirect.addEventListener('click',()=>{
console.log("click");
window.location.href='signup.html';
});
});