Return to login screen when refresh token expires
This commit is contained in:
parent
4f000c641b
commit
6759a0d022
|
|
@ -64,14 +64,13 @@ export class LoginPlugin implements Plugin {
|
|||
},
|
||||
|
||||
async onResponseError(error) {
|
||||
if (error.response.status !== 401 || error.response.config.hasRetriedRequest)
|
||||
if (error.response.status !== 401 || error.response.config.hasRetriedRequest)
|
||||
return;
|
||||
|
||||
const authContext = Container.get(AuthContext);
|
||||
const loginResponse = await loginApi.refreshAccessToken(authContext.getRefreshToken());
|
||||
|
||||
if (loginResponse.isAuthenticated) {
|
||||
|
||||
|
||||
await authContext.signinTokens(loginResponse.accessToken, loginResponse.refreshToken, true);
|
||||
|
||||
const t = await service.http({
|
||||
|
|
@ -85,6 +84,9 @@ export class LoginPlugin implements Plugin {
|
|||
|
||||
return t;
|
||||
}
|
||||
else {
|
||||
authContext.signOut();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export class LoginApi {
|
|||
}
|
||||
|
||||
async refreshAccessToken(refreshToken: string): Promise<LoginResponse> {
|
||||
const config: AxiosRequestConfig = {
|
||||
const config: AxiosRequestConfig = {
|
||||
baseURL: this.serverSettings.baseAddress,
|
||||
headers: {
|
||||
Authorization: `Bearer ${refreshToken}`
|
||||
|
|
@ -27,7 +27,9 @@ export class LoginApi {
|
|||
};
|
||||
|
||||
const httpClient = axios.create(config);
|
||||
const response = await httpClient.post<LoginResponse>(`identity/refresh-token`);
|
||||
return response.data;
|
||||
|
||||
return await httpClient.post<LoginResponse>(`identity/refresh-token`)
|
||||
.then(response => response.data)
|
||||
.catch(error => error.response)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue