|
document.addEventListener("DOMContentLoaded", () => { |
|
const signupForm = document.getElementById("signupForm"); |
|
const loginForm = document.getElementById("loginForm"); |
|
|
|
if (signupForm) { |
|
signupForm.addEventListener("submit", async (e) => { |
|
e.preventDefault(); |
|
const name = document.getElementById("name").value; |
|
const email = document.getElementById("email").value; |
|
const password = document.getElementById("password").value; |
|
|
|
const response = await fetch("/api/signup", { |
|
method: "POST", |
|
headers: { "Content-Type": "application/json" }, |
|
body: JSON.stringify({ name, email, password }), |
|
}); |
|
|
|
const data = await response.json(); |
|
document.getElementById("signupMessage").innerText = data.message; |
|
}); |
|
} |
|
|
|
if (loginForm) { |
|
loginForm.addEventListener("submit", async (e) => { |
|
e.preventDefault(); |
|
const email = document.getElementById("email").value; |
|
const password = document.getElementById("password").value; |
|
|
|
const response = await fetch("/api/login", { |
|
method: "POST", |
|
headers: { "Content-Type": "application/json" }, |
|
body: JSON.stringify({ email, password }), |
|
}); |
|
|
|
const data = await response.json(); |
|
document.getElementById("loginMessage").innerText = data.message; |
|
|
|
if (data.redirect) { |
|
window.location.href = data.redirect; |
|
} |
|
}); |
|
} |
|
}); |
|
|