mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 12:25:44 -05:00
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import i18next from 'i18next';
|
|
import { toast } from 'sonner';
|
|
|
|
import { setCurrentUserQueryData } from '@/api/account/queries';
|
|
import {
|
|
clientDisableTwoFactorAuthenticationMutation,
|
|
clientEnableTwoFactorAuthenticationMutation,
|
|
clientGetTwoFactorSetupOptions,
|
|
} from '@/api/generated/@tanstack/react-query.gen';
|
|
import { notifyHttpError } from '@/plugins/notifications';
|
|
|
|
export const useAccountTwoFactorToken = (enabled = true) => useQuery({ ...clientGetTwoFactorSetupOptions(), enabled });
|
|
|
|
export const useEnableAccountTwoFactor = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
...clientEnableTwoFactorAuthenticationMutation(),
|
|
onSuccess: () => {
|
|
setCurrentUserQueryData(queryClient, { useTotp: true });
|
|
toast.success(i18next.t('Two-step verification enabled'));
|
|
},
|
|
onError: (error) => notifyHttpError(error, i18next.t('Unable to enable two-step verification')),
|
|
});
|
|
};
|
|
|
|
export const useDisableAccountTwoFactor = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
...clientDisableTwoFactorAuthenticationMutation(),
|
|
onSuccess: () => {
|
|
setCurrentUserQueryData(queryClient, { useTotp: false });
|
|
toast.success(i18next.t('Two-step verification disabled'));
|
|
},
|
|
onError: (error) => notifyHttpError(error, i18next.t('Unable to disable two-step verification')),
|
|
});
|
|
};
|