20 lines
775 B
TypeScript
20 lines
775 B
TypeScript
import type { AuthResponse } from "../types";
|
|
|
|
const AUTH_BASE = `${import.meta.env.VITE_API_BASE_URL ?? ""}/api/auth`;
|
|
|
|
export async function login(email: string, password: string): Promise<AuthResponse> {
|
|
const res = await fetch(`${AUTH_BASE}/login`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ email, password }),
|
|
});
|
|
if (!res.ok) throw new Error(`Login failed: ${res.status}`);
|
|
return res.json() as Promise<AuthResponse>;
|
|
}
|
|
|
|
export async function refreshToken(token: string): Promise<AuthResponse> {
|
|
const res = await fetch(`${AUTH_BASE}/refresh/token?token=${encodeURIComponent(token)}`);
|
|
if (!res.ok) throw new Error(`Refresh failed: ${res.status}`);
|
|
return res.json() as Promise<AuthResponse>;
|
|
}
|