first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import {useMutation} from '@tanstack/react-query';
import {BackendResponse} from '@common/http/backend-response/backend-response';
import {apiClient} from '@common/http/query-client';
import {UseFormReturn} from 'react-hook-form';
import {onFormQueryError} from '@common/errors/on-form-query-error';
interface Response extends BackendResponse {}
export interface ConfirmTwoFactorPayload {
code: string;
}
export function useConfirmTwoFactor(
form: UseFormReturn<ConfirmTwoFactorPayload>,
) {
return useMutation({
mutationFn: (payload: ConfirmTwoFactorPayload) => confirm(payload),
onError: r => onFormQueryError(r, form),
});
}
function confirm(payload: ConfirmTwoFactorPayload): Promise<Response> {
return apiClient
.post('auth/user/confirmed-two-factor-authentication', payload)
.then(response => response.data);
}

View File

@@ -0,0 +1,19 @@
import {useMutation} from '@tanstack/react-query';
import {BackendResponse} from '@common/http/backend-response/backend-response';
import {apiClient} from '@common/http/query-client';
import {showHttpErrorToast} from '@common/utils/http/show-http-error-toast';
interface Response extends BackendResponse {}
export function useDisableTwoFactor() {
return useMutation({
mutationFn: disable,
onError: r => showHttpErrorToast(r),
});
}
function disable(): Promise<Response> {
return apiClient
.delete('auth/user/two-factor-authentication')
.then(response => response.data);
}

View File

@@ -0,0 +1,19 @@
import {useMutation} from '@tanstack/react-query';
import {BackendResponse} from '@common/http/backend-response/backend-response';
import {apiClient} from '@common/http/query-client';
import {showHttpErrorToast} from '@common/utils/http/show-http-error-toast';
interface Response extends BackendResponse {}
export function useEnableTwoFactor() {
return useMutation({
mutationFn: enable,
onError: r => showHttpErrorToast(r),
});
}
function enable(): Promise<Response> {
return apiClient
.post('auth/user/two-factor-authentication')
.then(response => response.data);
}

View File

@@ -0,0 +1,19 @@
import {useMutation} from '@tanstack/react-query';
import {BackendResponse} from '@common/http/backend-response/backend-response';
import {apiClient} from '@common/http/query-client';
import {showHttpErrorToast} from '@common/utils/http/show-http-error-toast';
interface Response extends BackendResponse {}
export function useRegenerateTwoFactorCodes() {
return useMutation({
mutationFn: () => regenerate(),
onError: r => showHttpErrorToast(r),
});
}
function regenerate(): Promise<Response> {
return apiClient
.post('auth/user/two-factor-recovery-codes')
.then(response => response.data);
}

View File

@@ -0,0 +1,37 @@
import {useMutation} from '@tanstack/react-query';
import {BackendResponse} from '@common/http/backend-response/backend-response';
import {apiClient} from '@common/http/query-client';
import {UseFormReturn} from 'react-hook-form';
import {onFormQueryError} from '@common/errors/on-form-query-error';
import {useHandleLoginSuccess} from '@common/auth/requests/use-login';
interface Response extends BackendResponse {
bootstrapData: string;
two_factor: false;
}
export interface TwoFactorChallengePayload {
code?: string;
recovery_code?: string;
}
export function useTwoFactorChallenge(
form: UseFormReturn<TwoFactorChallengePayload>,
) {
const handleSuccess = useHandleLoginSuccess();
return useMutation({
mutationFn: (payload: TwoFactorChallengePayload) =>
completeChallenge(payload),
onSuccess: response => {
handleSuccess(response);
},
onError: r => onFormQueryError(r, form),
});
}
function completeChallenge(
payload: TwoFactorChallengePayload,
): Promise<Response> {
return apiClient
.post('auth/two-factor-challenge', payload)
.then(response => response.data);
}

View File

@@ -0,0 +1,21 @@
import {useQuery} from '@tanstack/react-query';
import {BackendResponse} from '@common/http/backend-response/backend-response';
import {apiClient} from '@common/http/query-client';
interface Response extends BackendResponse {
svg: string;
secret: string;
}
export function useTwoFactorQrCode() {
return useQuery({
queryKey: ['two-factor-qr-code'],
queryFn: () => fetchCode(),
});
}
function fetchCode(): Promise<Response> {
return apiClient
.get('auth/user/two-factor/qr-code')
.then(response => response.data);
}