- Adjusted inconsistent formatting for better readability across components and services. - Enhanced type safety by adding placeholders for ignored error parameters and improving types across services. - Improved component organization by reordering imports consistently and applying formatting updates in UI components.
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import api from "@/lib/api";
|
|
import type {
|
|
LoginResponse,
|
|
RegisterPayload,
|
|
TwoFactorSetupResponse,
|
|
} from "@/types/auth";
|
|
|
|
export const AuthService = {
|
|
async login(email: string, password: string): Promise<LoginResponse> {
|
|
const { data } = await api.post<LoginResponse>("/auth/login", {
|
|
email,
|
|
password,
|
|
});
|
|
return data;
|
|
},
|
|
|
|
async verify2fa(userId: string, token: string): Promise<LoginResponse> {
|
|
const { data } = await api.post<LoginResponse>("/auth/verify-2fa", {
|
|
userId,
|
|
token,
|
|
});
|
|
return data;
|
|
},
|
|
|
|
async register(payload: RegisterPayload): Promise<void> {
|
|
await api.post("/auth/register", payload);
|
|
},
|
|
|
|
async logout(): Promise<void> {
|
|
await api.post("/auth/logout");
|
|
},
|
|
|
|
async refresh(): Promise<void> {
|
|
await api.post("/auth/refresh");
|
|
},
|
|
|
|
async setup2fa(): Promise<TwoFactorSetupResponse> {
|
|
const { data } = await api.post<TwoFactorSetupResponse>(
|
|
"/users/me/2fa/setup",
|
|
);
|
|
return data;
|
|
},
|
|
|
|
async enable2fa(token: string): Promise<void> {
|
|
await api.post("/users/me/2fa/enable", { token });
|
|
},
|
|
|
|
async disable2fa(token: string): Promise<void> {
|
|
await api.post("/users/me/2fa/disable", { token });
|
|
},
|
|
};
|