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)
|
# Variabili d'ambiente (MAI in git)
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
|
||||||
|
|
||||||
# Log
|
# Log
|
||||||
logs/
|
logs/
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue