Files
Messenger/web/src/api/auth.ts
benya e685a38be6
Some checks failed
CI / test (push) Failing after 33s
feat(auth): add active sessions management
- 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
2026-03-08 11:41:03 +03:00

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");
}