add: auth functionality basics

This commit is contained in:
Mahyar Khanbolooki
2025-07-01 19:30:54 +03:30
parent f1301140ba
commit ef63706116
10 changed files with 99 additions and 98 deletions
+14
View File
@@ -0,0 +1,14 @@
import { checkUserExists } from "@/lib/api/auth"
import { useQueryClient } from "@tanstack/react-query"
export const useCheckUserExistsLazy = () => {
const queryClient = useQueryClient()
const run = (phone: string) =>
queryClient.fetchQuery({
queryKey: ['checkUserExists', phone],
queryFn: () => checkUserExists(phone),
})
return { run }
}
+11
View File
@@ -0,0 +1,11 @@
import { useMutation } from '@tanstack/react-query'
import { login } from '@/lib/api/auth'
import { useAuthStore } from '@/zustand/userStore'
export const useLogin = () =>
useMutation({
mutationFn: login,
onSuccess: (data) => {
useAuthStore.getState().login(data.user)
},
})
+11
View File
@@ -0,0 +1,11 @@
import { useMutation } from '@tanstack/react-query'
import { signup } from '@/lib/api/auth'
import { useAuthStore } from '@/zustand/userStore'
export const useSignup = () =>
useMutation({
mutationFn: signup,
onSuccess: (data) => {
useAuthStore.getState().login(data.user)
},
})