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

This commit is contained in:
Prateek Shourya 2025-07-07 19:52:18 +05:30 committed by GitHub
parent e306a92adb
commit a2a62e2731
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View file

@ -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)

View file

@ -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;
}

View file

@ -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;
});
}