feat(auth): create login/register mutation hooks

This commit is contained in:
ngc2207 2025-01-31 16:41:33 +08:00
parent 531288f57a
commit 90853fa69a
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import { client } from "@/lib/rpc";
import { useMutation } from "@tanstack/react-query";
import { InferRequestType, InferResponseType } from "hono";
type ResponseType = InferResponseType<(typeof client.api.auth.login)["$post"]>;
type RequestType = InferRequestType<(typeof client.api.auth.login)["$post"]>;
export const useLogin = () => {
const mutation = useMutation<ResponseType, Error, RequestType>({
mutationFn: async ({ json }) => {
const response = await client.api.auth.login["$post"]({
json,
});
return await response.json();
},
});
return mutation;
};

View File

@ -0,0 +1,22 @@
import { client } from "@/lib/rpc";
import { useMutation } from "@tanstack/react-query";
import { InferRequestType, InferResponseType } from "hono";
type ResponseType = InferResponseType<
(typeof client.api.auth.register)["$post"]
>;
type RequestType = InferRequestType<(typeof client.api.auth.register)["$post"]>;
export const useRegister = () => {
const mutation = useMutation<ResponseType, Error, RequestType>({
mutationFn: async ({ json }) => {
const response = await client.api.auth.register["$post"]({
json,
});
return await response.json();
},
});
return mutation;
};