-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (25 loc) · 952 Bytes
/
script.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
document.getElementById('loginForm').addEventListener('submit', async function (e) {
e.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
try {
// Fetch user from Supabase
const { data, error } = await supabase
.from('users')
.select('*')
.eq('username', username)
.single();
if (error || !data) {
document.getElementById('error-message').textContent = 'Invalid Username!';
return;
}
if (data.password === password) { // For simplicity, password is not hashed. Use hashing in production.
window.location.href = 'admin.html';
} else {
document.getElementById('error-message').textContent = 'Incorrect Password!';
}
} catch (err) {
console.error(err);
document.getElementById('error-message').textContent = 'Something went wrong!';
}
});