add: auth functionality basics
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
@@ -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)
|
||||
},
|
||||
})
|
||||
@@ -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)
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user