mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-07-09 13:27:45 +00:00
feat(DevWeb): Projet - Login page, Login Api
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
const loginForm = document.getElementById("loginForm");
|
||||
|
||||
loginForm.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(loginForm);
|
||||
const data = {};
|
||||
formData.forEach((value, key) => data[key] = value);
|
||||
|
||||
const action = loginForm.getAttribute("action")
|
||||
const endpoint = loginForm.getAttribute("data-login-endpoint");
|
||||
const method = loginForm.getAttribute("method")
|
||||
|
||||
fetch(endpoint, {
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(data),
|
||||
method,
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data)
|
||||
window.location.href = action;
|
||||
})
|
||||
.catch(error => console.error("Error:", error))
|
||||
;
|
||||
});
|
||||
Reference in New Issue
Block a user