diff --git a/src/features/auth/api/use-login.ts b/src/features/auth/api/use-login.ts new file mode 100644 index 0000000..1d7cc49 --- /dev/null +++ b/src/features/auth/api/use-login.ts @@ -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({ + mutationFn: async ({ json }) => { + const response = await client.api.auth.login["$post"]({ + json, + }); + return await response.json(); + }, + }); + + return mutation; +}; diff --git a/src/features/auth/api/use-register.ts b/src/features/auth/api/use-register.ts new file mode 100644 index 0000000..cd94191 --- /dev/null +++ b/src/features/auth/api/use-register.ts @@ -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({ + mutationFn: async ({ json }) => { + const response = await client.api.auth.register["$post"]({ + json, + }); + return await response.json(); + }, + }); + + return mutation; +};