mirror of
https://gitlab.massbug.com/massbug/judge4c.git
synced 2025-07-04 11:10:54 +00:00
feat(auth): create login/register mutation hooks
This commit is contained in:
parent
531288f57a
commit
90853fa69a
20
src/features/auth/api/use-login.ts
Normal file
20
src/features/auth/api/use-login.ts
Normal 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;
|
||||
};
|
22
src/features/auth/api/use-register.ts
Normal file
22
src/features/auth/api/use-register.ts
Normal 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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user