31 lines
883 B
TypeScript
31 lines
883 B
TypeScript
import { httpClient } from '../../../lib/httpClient';
|
|
import type { User } from '../../../lib/types';
|
|
|
|
export class AuthApi {
|
|
static async login(username: string, password: string) {
|
|
return httpClient.request<{ token: string; user: User }>('/auth/login', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ username, password }),
|
|
});
|
|
}
|
|
|
|
static async register(username: string, displayName: string, password: string, bio?: string) {
|
|
return httpClient.request<{ token: string; user: User }>('/auth/register', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ username, displayName, password, bio }),
|
|
});
|
|
}
|
|
|
|
static async getMe() {
|
|
return httpClient.request<{ user: User }>('/auth/me');
|
|
}
|
|
|
|
static async getConfig() {
|
|
return httpClient.request<any>('/config');
|
|
}
|
|
|
|
static setToken(token: string | null) {
|
|
httpClient.setToken(token);
|
|
}
|
|
}
|