auth(2fa): add one-time recovery codes with regenerate/status APIs
All checks were successful
CI / test (push) Successful in 40s
All checks were successful
CI / test (push) Successful in 40s
This commit is contained in:
@@ -5,8 +5,13 @@ export async function registerRequest(email: string, name: string, username: str
|
||||
await http.post("/auth/register", { email, name, username, password });
|
||||
}
|
||||
|
||||
export async function loginRequest(email: string, password: string, otpCode?: string): Promise<TokenPair> {
|
||||
const { data } = await http.post<TokenPair>("/auth/login", { email, password, otp_code: otpCode || undefined });
|
||||
export async function loginRequest(email: string, password: string, otpCode?: string, recoveryCode?: string): Promise<TokenPair> {
|
||||
const { data } = await http.post<TokenPair>("/auth/login", {
|
||||
email,
|
||||
password,
|
||||
otp_code: otpCode || undefined,
|
||||
recovery_code: recoveryCode || undefined,
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -62,3 +67,21 @@ export async function enableTwoFactor(code: string): Promise<void> {
|
||||
export async function disableTwoFactor(code: string): Promise<void> {
|
||||
await http.post("/auth/2fa/disable", { code });
|
||||
}
|
||||
|
||||
export interface TwoFactorRecoveryStatusResponse {
|
||||
remaining_codes: number;
|
||||
}
|
||||
|
||||
export interface TwoFactorRecoveryCodesResponse {
|
||||
codes: string[];
|
||||
}
|
||||
|
||||
export async function getTwoFactorRecoveryStatus(): Promise<TwoFactorRecoveryStatusResponse> {
|
||||
const { data } = await http.get<TwoFactorRecoveryStatusResponse>("/auth/2fa/recovery-codes/status");
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function regenerateTwoFactorRecoveryCodes(code: string): Promise<TwoFactorRecoveryCodesResponse> {
|
||||
const { data } = await http.post<TwoFactorRecoveryCodesResponse>("/auth/2fa/recovery-codes/regenerate", { code });
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user