dburl geaendert
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
const form = document.getElementById("loginForm")
|
||||
const errorMessage = document.getElementById("errorMessage")
|
||||
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault()
|
||||
|
||||
const username = document.getElementById("username").value
|
||||
const password = document.getElementById("password").value
|
||||
|
||||
try {
|
||||
const response = await fetch("/auth/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({ username, password })
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
errorMessage.textContent = data.message
|
||||
return
|
||||
}
|
||||
|
||||
// Token speichern
|
||||
localStorage.setItem("token", data.token)
|
||||
|
||||
// Weiterleiten
|
||||
window.location.href = "dashboard.html"
|
||||
|
||||
} catch (err) {
|
||||
errorMessage.textContent = "Server nicht erreichbar"
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user