Files
hossein-por-shop/frontend/composables/api/auth/useSignIn.ts
T
2025-02-21 23:12:30 +03:30

39 lines
732 B
TypeScript

// imports
import { useMutation } from "@tanstack/vue-query";
import { API_ENDPOINTS } from "~/constants";
// types
export type SignInRequest = {
otp: string;
phone: string;
};
export type SignInResponse = {
access: string;
refresh: string;
};
const useSignIn = () => {
// state
const { $axios: axios } = useNuxtApp();
// methods
const handleSignIn = async (variables: SignInRequest) => {
const { data } = await axios.post<SignInResponse>(
`${API_ENDPOINTS.auth.signin}`,
variables
);
return data;
};
return useMutation({
mutationFn: (variables: SignInRequest) => handleSignIn(variables),
});
};
export default useSignIn;