mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
[WEB-1564] chore: add interceptor to handle 401 errors and redirect users to login page. (#4788)
This commit is contained in:
parent
4e5ca88e5e
commit
47dfb8797f
@ -11,6 +11,20 @@ export abstract class APIService {
|
|||||||
baseURL,
|
baseURL,
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.setupInterceptors();
|
||||||
|
}
|
||||||
|
|
||||||
|
private setupInterceptors() {
|
||||||
|
this.axiosInstance.interceptors.response.use(
|
||||||
|
(response) => response,
|
||||||
|
(error) => {
|
||||||
|
if (error.response && error.response.status === 401) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url: string, params = {}, config = {}) {
|
get(url: string, params = {}, config = {}) {
|
||||||
|
@ -46,7 +46,8 @@ export class UserService extends APIService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async currentUser(): Promise<IUser> {
|
async currentUser(): Promise<IUser> {
|
||||||
return this.get("/api/users/me/")
|
// Using validateStatus: null to bypass interceptors for unauthorized errors.
|
||||||
|
return this.get("/api/users/me/", { validateStatus: null })
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw error?.response;
|
throw error?.response;
|
||||||
|
Loading…
Reference in New Issue
Block a user