main
ts 67 lines 1.68 KB
Raw
1 import type { FlaskBaseResponse } from "@/types/flask.d"
2 import { HttpClient } from "../httpClient"
3
4 export interface TOTPSetupResponse {
5 secret: string
6 otpauth_url: string
7 qr_data_uri: string
8 backup_codes: string[]
9 }
10
11 export interface TOTPStatusResponse {
12 enabled: boolean
13 }
14
15 export interface TOTPBackupCodesResponse {
16 backup_codes: string[]
17 }
18
19 export interface TOTPValidateResponse {
20 access_token: string
21 token_type: string
22 }
23
24 export interface TOTPValidateRequest {
25 temp_token: string
26 code?: string
27 backup_code?: string
28 }
29
30 export interface TOTPDeleteRequest {
31 code?: string
32 backup_code?: string
33 }
34
35 export default {
36 /** Get 2FA status for current user */
37 getStatus() {
38 return HttpClient.get<FlaskBaseResponse & TOTPStatusResponse>("/auth/2fa/status")
39 },
40
41 /** Start 2FA setup — get QR code and backup codes */
42 setup() {
43 return HttpClient.post<FlaskBaseResponse & TOTPSetupResponse>("/auth/2fa/setup")
44 },
45
46 /** Verify setup with a TOTP code to activate 2FA */
47 verifySetup(code: string) {
48 return HttpClient.post<FlaskBaseResponse>("/auth/2fa/verify-setup", { code })
49 },
50
51 /** Disable 2FA (requires TOTP code or backup code) */
52 disable(payload: TOTPDeleteRequest) {
53 return HttpClient.delete<FlaskBaseResponse>("/auth/2fa/disable", { data: payload })
54 },
55
56 /** Validate 2FA code during login (uses temp_token, no auth header) */
57 validate(payload: TOTPValidateRequest) {
58 return HttpClient.post<FlaskBaseResponse & TOTPValidateResponse>("/auth/2fa/validate", payload)
59 },
60
61 /** Regenerate backup codes (requires TOTP code) */
62 regenerateBackupCodes(code: string) {
63 return HttpClient.post<FlaskBaseResponse & TOTPBackupCodesResponse>("/auth/2fa/backup-codes/regenerate", {
64 code
65 })
66 }
67 }