-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
44 lines (37 loc) · 1.49 KB
/
Copy pathauth.js
File metadata and controls
44 lines (37 loc) · 1.49 KB
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
if (document.getElementById('signupForm')) {
document.getElementById('signupForm').addEventListener('submit', function (e) {
e.preventDefault();
const name = document.getElementById('signupName').value;
const email = document.getElementById('signupEmail').value;
const password = document.getElementById('signupPassword').value;
console.log("Signup inputs:", name, email, password);
if (!name || !email || !password) {
alert("Please fill all fields.");
return;
}
const user = { name, email, password };
try {
localStorage.setItem(email, JSON.stringify(user));
console.log("User saved. Redirecting to login page...");
window.location.href = "index.html"; // Can change to window.location.replace() as well
} catch (err) {
console.error("Error saving user or redirecting:", err);
alert("Something went wrong. Check the console for details.");
}
});
}
// Login logic
if (document.getElementById('loginForm')) {
document.getElementById('loginForm').addEventListener('submit', function (e) {
e.preventDefault();
const email = document.getElementById('loginEmail').value;
const password = document.getElementById('loginPassword').value;
const storedUser = JSON.parse(localStorage.getItem(email));
if (storedUser && storedUser.password === password) {
localStorage.setItem('loggedInUser', email);
window.location.href = 'dashboard.html';
} else {
alert('Invalid credentials');
}
});
}