mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-19 06:32:58 +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) {
|
function requestAccessToken(refreshToken, dispatch) {
|
||||||
let promise;
|
|
||||||
if (refreshToken) {
|
if (refreshToken) {
|
||||||
promise = authentication.requestToken(refreshToken);
|
return authentication.requestToken(refreshToken)
|
||||||
} else {
|
|
||||||
promise = Promise.reject();
|
|
||||||
}
|
|
||||||
|
|
||||||
return promise
|
|
||||||
.then(({token}) => dispatch(updateToken(token)))
|
.then(({token}) => dispatch(updateToken(token)))
|
||||||
.catch(() => dispatch(logoutAll()));
|
.catch((resp = {}) => {
|
||||||
|
if (resp.originalResponse && resp.originalResponse.status >= 500) {
|
||||||
|
return Promise.reject(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 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 = {
|
const account = {
|
||||||
token: 'realy bad token',
|
token: 'realy bad token',
|
||||||
refreshToken
|
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', () => {
|
it('should not be applied if no token', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user