modifiche al login
This commit is contained in:
parent
1d7dc4700f
commit
4ff685557f
3 changed files with 17 additions and 8 deletions
|
|
@ -1 +0,0 @@
|
|||
VITE_API_URL=http://localhost:3003
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -11,7 +11,6 @@ dist-ssr/
|
|||
# Variabili d'ambiente (MAI in git)
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Log
|
||||
logs/
|
||||
|
|
|
|||
|
|
@ -44,29 +44,40 @@ export async function login(email: string, password: string): Promise<void> {
|
|||
email,
|
||||
password,
|
||||
redirect: "false",
|
||||
json: "true",
|
||||
});
|
||||
|
||||
const response = await fetch(`${API_URL}/api/auth/callback/credentials`, {
|
||||
method: "POST",
|
||||
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,
|
||||
});
|
||||
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok || data.error) {
|
||||
if (response.type === "opaqueredirect" || response.status === 302) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
export async function logout(): Promise<void> {
|
||||
const csrfToken = await getCsrfToken();
|
||||
const body = new URLSearchParams({ csrfToken, json: "true" });
|
||||
const body = new URLSearchParams({ csrfToken });
|
||||
await fetch(`${API_URL}/api/auth/signout`, {
|
||||
method: "POST",
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue