From a2a62e2731728f2954259d002a090d310f17a6a2 Mon Sep 17 00:00:00 2001 From: Prateek Shourya Date: Mon, 7 Jul 2025 19:52:18 +0530 Subject: [PATCH] [WEB-4453] fix: enable revalidation on focus and stale data for current user fetch to handle 401 errors (#7353) --- apps/space/core/lib/instance-provider.tsx | 4 ++-- apps/space/core/store/user.store.ts | 4 ++++ packages/services/src/user/user.service.ts | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/space/core/lib/instance-provider.tsx b/apps/space/core/lib/instance-provider.tsx index 06056364f..d0e473dfe 100644 --- a/apps/space/core/lib/instance-provider.tsx +++ b/apps/space/core/lib/instance-provider.tsx @@ -32,8 +32,8 @@ export const InstanceProvider = observer(({ children }: { children: ReactNode }) }); useSWR("CURRENT_USER", () => fetchCurrentUser(), { shouldRetryOnError: false, - revalidateOnFocus: false, - revalidateIfStale: false, + revalidateOnFocus: true, + revalidateIfStale: true, }); if (!instance && !error) diff --git a/apps/space/core/store/user.store.ts b/apps/space/core/store/user.store.ts index 510545bd3..438b67aeb 100644 --- a/apps/space/core/store/user.store.ts +++ b/apps/space/core/store/user.store.ts @@ -1,3 +1,4 @@ +import { AxiosError } from "axios"; import set from "lodash/set"; import { action, computed, makeObservable, observable, runInAction } from "mobx"; // plane imports @@ -112,6 +113,9 @@ export class UserStore implements IUserStore { status: "user-fetch-error", message: "Failed to fetch current user", }; + if (error instanceof AxiosError && error.status === 401) { + this.data = undefined; + } }); throw error; } diff --git a/packages/services/src/user/user.service.ts b/packages/services/src/user/user.service.ts index 339297662..c177b1ffd 100644 --- a/packages/services/src/user/user.service.ts +++ b/packages/services/src/user/user.service.ts @@ -26,7 +26,7 @@ export class UserService extends APIService { return this.get("/api/users/me/") .then((response) => response?.data) .catch((error) => { - throw error?.response; + throw error; }); }