Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: handle session invalidation on 401 error by logging out signed-in users

YuTengjing499bd4a7228c
diff --git a/src/libs/trpc/client/lambda.ts b/src/libs/trpc/client/lambda.ts
index 11d16e5ed3a..b41f569392f 100644
--- a/src/libs/trpc/client/lambda.ts
+++ b/src/libs/trpc/client/lambda.ts
@@ -43,6 +43,13 @@ const errorHandlingLink: TRPCLink<LambdaRouter> = () => {
// Desktop app doesn't have the web auth routes like `/signin`,
// so skip the login redirect/notification there.
if (!isDesktop) {
+ const { getUserStoreState } = await import('@/store/user/store');
+ const { isSignedIn, logout } = getUserStoreState();
+ // If user is still marked as signed in but got 401,
+ // session is invalid - clear client state first
+ if (isSignedIn) {
+ await logout();
+ }
const { loginRequired } =
await import('@/components/Error/loginRequiredNotification');
loginRequired.redirect();