Files
The_DisExcel_project/frontend/src/api/LoginAPI/Auth.ts
T
2026-09-30 16:18:36 +03:00

15 lines
517 B
TypeScript

import { API_URL, 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",
});
if (!res.ok) throw new Error("Неверный email или пароль");
const data = await res.json();
setAccessToken(data.access_token);
return data;
}