From 90853fa69a4d8c234e0f4577e092075b796bfd24 Mon Sep 17 00:00:00 2001 From: ngc2207 Date: Fri, 31 Jan 2025 16:41:33 +0800 Subject: [PATCH] feat(auth): create login/register mutation hooks --- src/features/auth/api/use-login.ts | 20 ++++++++++++++++++++ src/features/auth/api/use-register.ts | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/features/auth/api/use-login.ts create mode 100644 src/features/auth/api/use-register.ts 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; +};