-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (43 loc) · 1.68 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
// Function to toggle between sign-up and sign-in forms
const toggle = () => {
const container = document.getElementById('container');
container.classList.toggle('sign-in');
container.classList.toggle('sign-up');
};
// Function to handle user sign-up
const signup = async () => {
const name = document.getElementById('signup-name').value;
const email = document.getElementById('signup-email').value;
const password = document.getElementById('signup-password').value;
const confirmPassword = document.getElementById('signup-confirm-password').value;
if (password !== confirmPassword) {
alert('Passwords do not match.');
return;
}
try {
// Create a new user with email and password
await firebase.auth().createUserWithEmailAndPassword(email, password);
// Update the user's display name with the provided name
await firebase.auth().currentUser.updateProfile({
displayName: name
});
alert('Sign up successful! You can now log in.');
} catch (error) {
alert(error.message);
}
};
// Function to handle user login
const login = async () => {
const username = document.getElementById('login-username').value;
const password = document.getElementById('login-password').value;
try {
// Sign in with email and password
await firebase.auth().signInWithEmailAndPassword(username, password);
alert('Login successful!');
} catch (error) {
alert(error.message);
}
};
// Initialize with sign-in form
const container = document.getElementById('container');
container.classList.add('sign-in');