mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-26 23:10:20 +05:30
#303: do not logout if token refresh failed due to 5xx error
This commit is contained in:
parent
4074a65329
commit
1c467bc7bd
@ -68,16 +68,19 @@ export default function refreshTokenMiddleware({dispatch, getState}) {
|
||||
}
|
||||
|
||||
function requestAccessToken(refreshToken, dispatch) {
|
||||
let promise;
|
||||
if (refreshToken) {
|
||||
promise = authentication.requestToken(refreshToken);
|
||||
} else {
|
||||
promise = Promise.reject();
|
||||
return authentication.requestToken(refreshToken)
|
||||
.then(({token}) => dispatch(updateToken(token)))
|
||||
.catch((resp = {}) => {
|
||||
if (resp.originalResponse && resp.originalResponse.status >= 500) {
|
||||
return Promise.reject(resp);
|
||||
}
|
||||
|
||||
return dispatch(logoutAll());
|
||||
});
|
||||
}
|
||||
|
||||
return promise
|
||||
.then(({token}) => dispatch(updateToken(token)))
|
||||
.catch(() => dispatch(logoutAll()));
|
||||
return dispatch(logoutAll());
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,7 +110,7 @@ describe('refreshTokenMiddleware', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should if token can not be parsed', () => {
|
||||
it('should logout if token can not be parsed', () => {
|
||||
const account = {
|
||||
token: 'realy bad token',
|
||||
refreshToken
|
||||
@ -143,6 +143,22 @@ describe('refreshTokenMiddleware', () => {
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('should not logout if request failed with 5xx', () => {
|
||||
const resp = {
|
||||
originalResponse: {
|
||||
status: 500
|
||||
}
|
||||
};
|
||||
|
||||
authentication.requestToken.returns(Promise.reject(resp));
|
||||
|
||||
return expect(middleware.before({url: 'foo', options: {}}), 'to be rejected with', resp).then(() =>
|
||||
expect(dispatch, 'to have no calls satisfying', [
|
||||
{payload: {isGuest: true}}
|
||||
])
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not be applied if no token', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user