1+ import { useMutation , UseMutationOptions } from '@tanstack/react-query' ;
2+ import { apiClient } from '@/lib/api/client' ;
3+ import { queryKeys } from '../keys' ;
4+ import {
5+ RegisterInput ,
6+ LoginInput ,
7+ AuthResponse ,
8+ ApiError ,
9+ } from '../types' ;
10+
11+ /**
12+ * Mutation hook for user registration
13+ * @param options - Optional mutation options for callbacks and config
14+ * @returns Mutation object with mutate, isPending, isError, etc.
15+ */
16+ export function useRegisterMutation (
17+ options ?: UseMutationOptions < AuthResponse , ApiError , RegisterInput >
18+ ) {
19+ return useMutation < AuthResponse , ApiError , RegisterInput > ( {
20+ mutationKey : queryKeys . auth . register ,
21+ mutationFn : ( data : RegisterInput ) => apiClient . register ( data ) ,
22+ ...options ,
23+ } ) ;
24+ }
25+
26+ /**
27+ * Mutation hook for user login
28+ * @param options - Optional mutation options for callbacks and config
29+ * @returns Mutation object with mutate, isPending, isError, etc.
30+ */
31+ export function useLoginMutation (
32+ options ?: UseMutationOptions < AuthResponse , ApiError , LoginInput >
33+ ) {
34+ return useMutation < AuthResponse , ApiError , LoginInput > ( {
35+ mutationKey : queryKeys . auth . login ,
36+ mutationFn : ( data : LoginInput ) => apiClient . login ( data ) ,
37+ ...options ,
38+ } ) ;
39+ }
0 commit comments