modifiche al login
All checks were successful
Deploy to VPS / build (push) Successful in 19s
Deploy to VPS / deploy (push) Successful in 13s

This commit is contained in:
AV77web 2026-06-09 14:21:18 +02:00
parent 1d7dc4700f
commit 4ff685557f
3 changed files with 17 additions and 8 deletions

View file

@ -1 +0,0 @@
VITE_API_URL=http://localhost:3003

1
.gitignore vendored
View file

@ -11,7 +11,6 @@ dist-ssr/
# Variabili d'ambiente (MAI in git) # Variabili d'ambiente (MAI in git)
.env .env
.env.* .env.*
!.env.example
# Log # Log
logs/ logs/

View file

@ -44,29 +44,40 @@ export async function login(email: string, password: string): Promise<void> {
email, email,
password, password,
redirect: "false", redirect: "false",
json: "true",
}); });
const response = await fetch(`${API_URL}/api/auth/callback/credentials`, { const response = await fetch(`${API_URL}/api/auth/callback/credentials`, {
method: "POST", method: "POST",
credentials: "include", credentials: "include",
headers: { "Content-Type": "application/x-www-form-urlencoded" }, redirect: "manual",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-Auth-Return-Redirect": "1",
},
body, body,
}); });
const data = await response.json().catch(() => ({})); if (response.type === "opaqueredirect" || response.status === 302) {
if (!response.ok || data.error) { throw new Error("Login non riuscito: frontend non aggiornato o configurazione Auth errata");
}
const data = await response.json().catch(() => ({})) as { url?: string };
if (!response.ok || data.url?.includes("error=")) {
throw new Error("Credenziali non valide"); throw new Error("Credenziali non valide");
} }
} }
export async function logout(): Promise<void> { export async function logout(): Promise<void> {
const csrfToken = await getCsrfToken(); const csrfToken = await getCsrfToken();
const body = new URLSearchParams({ csrfToken, json: "true" }); const body = new URLSearchParams({ csrfToken });
await fetch(`${API_URL}/api/auth/signout`, { await fetch(`${API_URL}/api/auth/signout`, {
method: "POST", method: "POST",
credentials: "include", credentials: "include",
headers: { "Content-Type": "application/x-www-form-urlencoded" }, redirect: "manual",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-Auth-Return-Redirect": "1",
},
body, body,
}); });
} }