[WEB-4453] fix: enable revalidation on focus and stale data for current user fetch to handle 401 errors (#7353)
This commit is contained in:
parent
e306a92adb
commit
a2a62e2731
3 changed files with 7 additions and 3 deletions
|
|
@ -32,8 +32,8 @@ export const InstanceProvider = observer(({ children }: { children: ReactNode })
|
||||||
});
|
});
|
||||||
useSWR("CURRENT_USER", () => fetchCurrentUser(), {
|
useSWR("CURRENT_USER", () => fetchCurrentUser(), {
|
||||||
shouldRetryOnError: false,
|
shouldRetryOnError: false,
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: true,
|
||||||
revalidateIfStale: false,
|
revalidateIfStale: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!instance && !error)
|
if (!instance && !error)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { AxiosError } from "axios";
|
||||||
import set from "lodash/set";
|
import set from "lodash/set";
|
||||||
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
||||||
// plane imports
|
// plane imports
|
||||||
|
|
@ -112,6 +113,9 @@ export class UserStore implements IUserStore {
|
||||||
status: "user-fetch-error",
|
status: "user-fetch-error",
|
||||||
message: "Failed to fetch current user",
|
message: "Failed to fetch current user",
|
||||||
};
|
};
|
||||||
|
if (error instanceof AxiosError && error.status === 401) {
|
||||||
|
this.data = undefined;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export class UserService extends APIService {
|
||||||
return this.get("/api/users/me/")
|
return this.get("/api/users/me/")
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw error?.response;
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue