Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[WEB-4453] fix: enable revalidation on focus and stale data for current user fetch to handle 401 errors (#7353)

Prateek Shouryaa2a62e273172
diff --git a/apps/space/core/lib/instance-provider.tsx b/apps/space/core/lib/instance-provider.tsx
index 06056364f3..d0e473dfe8 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 510545bd35..438b67aeba 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 3392976625..c177b1ffd8 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;
});
}