add analytics-view
This commit is contained in:
19
analytics-view/src/api/authApi.ts
Normal file
19
analytics-view/src/api/authApi.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
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>;
|
||||
}
|
||||
Reference in New Issue
Block a user