save tokens localstorage, fix refresh sql query, added permissions

This commit is contained in:
2026-09-30 14:33:20 +03:00
parent 6a6a95e863
commit bcfd4acfad
18 changed files with 255 additions and 22 deletions
+7 -3
View File
@@ -1,14 +1,18 @@
import { API_URL, setAccessToken } from "../token";
import { API_URL, authFetch, setAccessToken } from "../token";
export async function login(email: string, password: string) {
const body = new URLSearchParams({ username: email, password });
const res = await fetch(`${API_URL}/protected/token`, {
method: "POST",
body,
credentials: "include",
body,
credentials: "include",
});
if (!res.ok) throw new Error("Неверный email или пароль");
const data = await res.json();
setAccessToken(data.access_token);
return data;
}
export async function logout() {
return authFetch("/protected/logout");
}