mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { useMutation } from '@tanstack/react-query';
|
|
import { toast } from 'sonner';
|
|
import {
|
|
authCompleteLoginCheckpointMutation,
|
|
authLoginMutation,
|
|
authLogoutMutation,
|
|
authRequestPasswordResetEmailMutation,
|
|
authResetPasswordMutation,
|
|
} from '@/api/generated/@tanstack/react-query.gen';
|
|
import { authGetCsrfCookie } from '@/api/generated/sdk.gen';
|
|
import { notifyHttpError } from '@/plugins/notifications';
|
|
|
|
export const useLogin = () =>
|
|
useMutation({
|
|
...authLoginMutation(),
|
|
onMutate: async () => {
|
|
await authGetCsrfCookie();
|
|
},
|
|
onError: (error) => notifyHttpError(error, 'Unable to log in'),
|
|
});
|
|
|
|
export const useLoginCheckpoint = () =>
|
|
useMutation({
|
|
...authCompleteLoginCheckpointMutation(),
|
|
onError: (error) => notifyHttpError(error, 'Unable to verify two-step code'),
|
|
});
|
|
|
|
export const useRequestPasswordResetEmail = () =>
|
|
useMutation({
|
|
...authRequestPasswordResetEmailMutation(),
|
|
onSuccess: (response) => toast.success(response.status || 'Password reset email sent'),
|
|
onError: (error) => notifyHttpError(error, 'Unable to request password reset'),
|
|
});
|
|
|
|
export const usePerformPasswordReset = () =>
|
|
useMutation({
|
|
...authResetPasswordMutation(),
|
|
onError: (error) => notifyHttpError(error, 'Unable to reset password'),
|
|
});
|
|
|
|
export const useLogout = () =>
|
|
useMutation({
|
|
...authLogoutMutation(),
|
|
onSettled: () => {
|
|
window.location.assign('/');
|
|
},
|
|
});
|