aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/utils
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-07-14 00:10:53 +0000
committerMohamed Bassem <me@mbassem.com>2025-07-14 00:10:53 +0000
commita3627569466677d3c0f585af3e04b7ce7a14249f (patch)
tree36304a164a86457ef50a709a0196c23db519265a /apps/web/components/utils
parent39fcda015b467be6c08d134fd45ec94204b08a09 (diff)
downloadkarakeep-a3627569466677d3c0f585af3e04b7ce7a14249f.tar.zst
fix: Clear search history on logout
Diffstat (limited to '')
-rw-r--r--apps/web/components/utils/ValidAccountCheck.tsx14
1 files changed, 8 insertions, 6 deletions
diff --git a/apps/web/components/utils/ValidAccountCheck.tsx b/apps/web/components/utils/ValidAccountCheck.tsx
index 12c11087..5ca5fd5c 100644
--- a/apps/web/components/utils/ValidAccountCheck.tsx
+++ b/apps/web/components/utils/ValidAccountCheck.tsx
@@ -1,13 +1,15 @@
"use client";
+import { useEffect } from "react";
+import { useRouter } from "next/navigation";
import { api } from "@/lib/trpc";
-import { signOut } from "next-auth/react";
/**
* This component is used to address a confusion when the JWT token exists but the user no longer exists in the database.
* So this component synchronusly checks if the user is still valid and if not, signs out the user.
*/
export default function ValidAccountCheck() {
+ const router = useRouter();
const { error } = api.users.whoami.useQuery(undefined, {
retry: (_failureCount, error) => {
if (error.data?.code === "UNAUTHORIZED") {
@@ -16,11 +18,11 @@ export default function ValidAccountCheck() {
return true;
},
});
- if (error?.data?.code === "UNAUTHORIZED") {
- signOut({
- callbackUrl: "/",
- });
- }
+ useEffect(() => {
+ if (error?.data?.code === "UNAUTHORIZED") {
+ router.push("/logout");
+ }
+ }, [error]);
return <></>;
}