Some checks failed
CI / test (push) Failing after 33s
- store refresh session metadata in redis (ip/user-agent/created_at) - add auth APIs: list sessions, revoke one, revoke all - add web privacy UI for active sessions
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { http } from "./http";
|
|
import type { AuthSession, AuthUser, TokenPair } from "../chat/types";
|
|
|
|
export async function registerRequest(email: string, name: string, username: string, password: string): Promise<void> {
|
|
await http.post("/auth/register", { email, name, username, password });
|
|
}
|
|
|
|
export async function loginRequest(email: string, password: string): Promise<TokenPair> {
|
|
const { data } = await http.post<TokenPair>("/auth/login", { email, password });
|
|
return data;
|
|
}
|
|
|
|
export async function refreshRequest(refreshToken: string): Promise<TokenPair> {
|
|
const { data } = await http.post<TokenPair>("/auth/refresh", { refresh_token: refreshToken });
|
|
return data;
|
|
}
|
|
|
|
export async function meRequest(): Promise<AuthUser> {
|
|
const { data } = await http.get<AuthUser>("/auth/me");
|
|
return data;
|
|
}
|
|
|
|
export async function listSessions(): Promise<AuthSession[]> {
|
|
const { data } = await http.get<AuthSession[]>("/auth/sessions");
|
|
return data;
|
|
}
|
|
|
|
export async function revokeSession(jti: string): Promise<void> {
|
|
await http.delete(`/auth/sessions/${jti}`);
|
|
}
|
|
|
|
export async function revokeAllSessions(): Promise<void> {
|
|
await http.delete("/auth/sessions");
|
|
}
|