initial
This commit is contained in:
36
frontend/src/api/auth.ts
Normal file
36
frontend/src/api/auth.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { clearAuthToken, request, setAuthToken } from "./client";
|
||||
|
||||
export interface LoginResponse {
|
||||
token: string;
|
||||
expiresAt: string;
|
||||
}
|
||||
|
||||
export interface AuthStatus {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export async function login(username: string, password: string): Promise<LoginResponse> {
|
||||
const result = await request<LoginResponse>("/auth/login", {
|
||||
method: "POST",
|
||||
body: { username, password },
|
||||
skipAuth: true
|
||||
});
|
||||
setAuthToken(result.token);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function signOut() {
|
||||
clearAuthToken();
|
||||
}
|
||||
|
||||
export function setToken(token: string | null) {
|
||||
if (token) {
|
||||
setAuthToken(token);
|
||||
} else {
|
||||
clearAuthToken();
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchAuthStatus(): Promise<AuthStatus> {
|
||||
return request<AuthStatus>("/auth/status", { method: "GET", skipAuth: true });
|
||||
}
|
||||
Reference in New Issue
Block a user