import { queryOptions, useMutation } from '@tanstack/react-query'; import { signIn, signOut, verifyOtp } from './action'; export function useAuthActions() { // Sign In Mutation const signInMutation = useMutation({ mutationKey: ["signIn"], mutationFn: async (formData: FormData) => { const response = await signIn(formData); // If the server action returns an error, treat it as an error for React Query if (response?.error) { throw new Error(response.error); } } }); const verifyOtpMutation = useMutation({ mutationKey: ["verifyOtp"], mutationFn: async (formData: FormData) => { const response = await verifyOtp(formData); // If the server action returns an error, treat it as an error for React Query if (response?.error) { throw new Error(response.error); } } }) const signOutMutation = useMutation({ mutationKey: ["signOut"], mutationFn: async () => { const response = await signOut(); // If the server action returns an error, treat it as an error for React Query if (response?.error) { throw new Error(response.error); } } }) return { signIn: signInMutation, verifyOtp: verifyOtpMutation, signOut: signOutMutation }; }