feat: delete users - not tested
This commit is contained in:
32
frontend/src/features/auth/hooks/useSignup.ts
Normal file
32
frontend/src/features/auth/hooks/useSignup.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @ai-summary React Query hook for user signup
|
||||
*/
|
||||
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import toast from 'react-hot-toast';
|
||||
import { authApi } from '../api/auth.api';
|
||||
import { SignupRequest } from '../types/auth.types';
|
||||
|
||||
interface ApiError {
|
||||
response?: {
|
||||
data?: {
|
||||
error?: string;
|
||||
message?: string;
|
||||
};
|
||||
status?: number;
|
||||
};
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export const useSignup = () => {
|
||||
return useMutation({
|
||||
mutationFn: (data: SignupRequest) => authApi.signup(data),
|
||||
onSuccess: () => {
|
||||
toast.success('Account created! Please check your email to verify your account.');
|
||||
},
|
||||
onError: (error: ApiError) => {
|
||||
const errorMessage = error.response?.data?.error || error.response?.data?.message || error.message || 'Failed to create account';
|
||||
toast.error(errorMessage);
|
||||
},
|
||||
});
|
||||
};
|
||||
54
frontend/src/features/auth/hooks/useVerifyStatus.ts
Normal file
54
frontend/src/features/auth/hooks/useVerifyStatus.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @ai-summary React Query hook for email verification status with polling
|
||||
*/
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useAuth0 } from '@auth0/auth0-react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { authApi } from '../api/auth.api';
|
||||
|
||||
interface ApiError {
|
||||
response?: {
|
||||
data?: {
|
||||
error?: string;
|
||||
message?: string;
|
||||
};
|
||||
};
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export const useVerifyStatus = (options?: { enablePolling?: boolean; onVerified?: () => void }) => {
|
||||
const { isAuthenticated, isLoading } = useAuth0();
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: ['verifyStatus'],
|
||||
queryFn: authApi.getVerifyStatus,
|
||||
enabled: isAuthenticated && !isLoading,
|
||||
refetchInterval: options?.enablePolling ? 5000 : false, // Poll every 5 seconds if enabled
|
||||
refetchIntervalInBackground: false,
|
||||
retry: 2,
|
||||
});
|
||||
|
||||
// Call onVerified callback when verification completes
|
||||
if (query.data?.emailVerified && options?.onVerified) {
|
||||
options.onVerified();
|
||||
}
|
||||
|
||||
return query;
|
||||
};
|
||||
|
||||
export const useResendVerification = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: () => authApi.resendVerification(),
|
||||
onSuccess: (data) => {
|
||||
toast.success(data.message || 'Verification email sent. Please check your inbox.');
|
||||
queryClient.invalidateQueries({ queryKey: ['verifyStatus'] });
|
||||
},
|
||||
onError: (error: ApiError) => {
|
||||
const errorMessage = error.response?.data?.error || error.response?.data?.message || error.message || 'Failed to resend verification email';
|
||||
toast.error(errorMessage);
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user