Ivan - Fix session [skip ci]

This commit is contained in:
ivan 2017-02-25 16:48:16 -03:00
parent a60f6e9cd9
commit 9e545ff110
2 changed files with 23 additions and 14 deletions

View File

@ -102,6 +102,7 @@ describe('Session Actions,', function () {
});
APICallMock.call.reset();
storeMock.dispatch.reset();
sessionStoreMock.isLoggedIn.returns(true)
});
after(function () {
@ -114,7 +115,7 @@ describe('Session Actions,', function () {
}));
});
it('should return CHECK_SESSION and dispatch SESSION_ACTIVE if session is active', function () {
it('should return CHECK_SESSION and dispatch SESSION_CHECKED if session is active', function () {
APICallMock.call.returns({
then: function (resolve) {
resolve({

View File

@ -97,23 +97,31 @@ export default {
initSession() {
return {
type: 'CHECK_SESSION',
payload: API.call({
path: '/user/check-session',
data: {}
}).then((result) => {
if (!result.data.sessionActive) {
if (sessionStore.isRememberDataExpired()) {
payload: new Promise((resolve, reject) => {
API.call({
path: '/user/check-session',
data: {}
}).then((result) => {
if (!result.data.sessionActive) {
if (sessionStore.isRememberDataExpired()) {
store.dispatch({
type: 'LOGOUT_FULFILLED'
});
} else {
store.dispatch(this.autoLogin());
}
resolve(result);
} else if(sessionStore.isLoggedIn()) {
store.dispatch({
type: 'LOGOUT_FULFILLED'
type: 'SESSION_CHECKED'
});
resolve(result);
} else {
store.dispatch(this.autoLogin());
reject(result);
}
} else if(sessionStore.isLoggedIn()) {
store.dispatch({
type: 'SESSION_CHECKED'
});
}
});
})
}
}