40 lines
1,022 B
TypeScript
40 lines
1,022 B
TypeScript
import axios from 'axios';
|
|
|
|
const API_BASE_URL = import.meta.env.VITE_API_URL || '/api/v1';
|
|
|
|
interface TwoFactorSetupResponse {
|
|
secret: string;
|
|
qr_code_url: string;
|
|
backup_codes: string[];
|
|
}
|
|
|
|
interface TwoFactorStatus {
|
|
enabled: boolean;
|
|
}
|
|
|
|
class TwoFactorService {
|
|
async getStatus(): Promise<TwoFactorStatus> {
|
|
const response = await axios.get(`${API_BASE_URL}/2fa/status`);
|
|
return response.data;
|
|
}
|
|
|
|
async setup(): Promise<TwoFactorSetupResponse> {
|
|
const response = await axios.post(`${API_BASE_URL}/2fa/setup`);
|
|
return response.data;
|
|
}
|
|
|
|
async enable(code: string): Promise<void> {
|
|
await axios.post(`${API_BASE_URL}/2fa/enable`, { code });
|
|
}
|
|
|
|
async disable(code: string): Promise<void> {
|
|
await axios.post(`${API_BASE_URL}/2fa/disable`, { code });
|
|
}
|
|
|
|
async verify(code: string): Promise<boolean> {
|
|
const response = await axios.post(`${API_BASE_URL}/2fa/verify`, { code });
|
|
return response.data.valid;
|
|
}
|
|
}
|
|
|
|
export const twoFactorService = new TwoFactorService();
|