diff --git a/src/features/auth/api/use-login.ts b/src/features/auth/api/use-login.ts index 1d7cc49..3825105 100644 --- a/src/features/auth/api/use-login.ts +++ b/src/features/auth/api/use-login.ts @@ -1,12 +1,16 @@ import { client } from "@/lib/rpc"; -import { useMutation } from "@tanstack/react-query"; +import { useRouter } from "next/navigation"; import { InferRequestType, InferResponseType } from "hono"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; type ResponseType = InferResponseType<(typeof client.api.auth.login)["$post"]>; type RequestType = InferRequestType<(typeof client.api.auth.login)["$post"]>; export const useLogin = () => { + const router = useRouter(); + const queryClient = useQueryClient(); + const mutation = useMutation({ mutationFn: async ({ json }) => { const response = await client.api.auth.login["$post"]({ @@ -14,6 +18,10 @@ export const useLogin = () => { }); return await response.json(); }, + onSuccess: () => { + router.refresh(); + queryClient.invalidateQueries({ queryKey: ["current"] }); + }, }); return mutation; diff --git a/src/features/auth/api/use-logout.ts b/src/features/auth/api/use-logout.ts index 05bf8f9..9d13910 100644 --- a/src/features/auth/api/use-logout.ts +++ b/src/features/auth/api/use-logout.ts @@ -1,10 +1,12 @@ import { client } from "@/lib/rpc"; import { InferResponseType } from "hono"; import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { useRouter } from "next/navigation"; type ResponseType = InferResponseType<(typeof client.api.auth.logout)["$post"]>; export const useLogout = () => { + const router = useRouter(); const queryClient = useQueryClient(); const mutation = useMutation({ @@ -13,6 +15,7 @@ export const useLogout = () => { return await response.json(); }, onSuccess: () => { + router.refresh(); queryClient.invalidateQueries({ queryKey: ["current"] }); }, }); diff --git a/src/features/auth/api/use-register.ts b/src/features/auth/api/use-register.ts index cd94191..b9cfc0a 100644 --- a/src/features/auth/api/use-register.ts +++ b/src/features/auth/api/use-register.ts @@ -1,6 +1,7 @@ import { client } from "@/lib/rpc"; -import { useMutation } from "@tanstack/react-query"; +import { useRouter } from "next/navigation"; import { InferRequestType, InferResponseType } from "hono"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; type ResponseType = InferResponseType< (typeof client.api.auth.register)["$post"] @@ -9,6 +10,9 @@ type ResponseType = InferResponseType< type RequestType = InferRequestType<(typeof client.api.auth.register)["$post"]>; export const useRegister = () => { + const router = useRouter(); + const queryClient = useQueryClient(); + const mutation = useMutation({ mutationFn: async ({ json }) => { const response = await client.api.auth.register["$post"]({ @@ -16,6 +20,10 @@ export const useRegister = () => { }); return await response.json(); }, + onSuccess: () => { + router.refresh(); + queryClient.invalidateQueries({ queryKey: ["current"] }); + }, }); return mutation;