2022-09-07 18:39:33 +05:00
|
|
|
import { getAccessToken } from '../utils/access-token-storage';
|
2019-08-31 04:07:25 +05:00
|
|
|
import ActionTypes from '../constants/ActionTypes';
|
|
|
|
|
|
|
|
const initialState = {
|
2022-09-07 18:39:33 +05:00
|
|
|
accessToken: getAccessToken(),
|
2019-08-31 04:07:25 +05:00
|
|
|
userId: null,
|
|
|
|
};
|
|
|
|
|
2022-02-09 00:56:01 +05:00
|
|
|
// eslint-disable-next-line default-param-last
|
2019-08-31 04:07:25 +05:00
|
|
|
export default (state = initialState, { type, payload }) => {
|
|
|
|
switch (type) {
|
2022-09-07 18:39:33 +05:00
|
|
|
case ActionTypes.AUTHENTICATE__SUCCESS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
accessToken: payload.accessToken,
|
|
|
|
};
|
2021-06-24 01:05:22 +05:00
|
|
|
case ActionTypes.SOCKET_RECONNECT_HANDLE:
|
|
|
|
case ActionTypes.CORE_INITIALIZE:
|
2019-08-31 04:07:25 +05:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
userId: payload.user.id,
|
|
|
|
};
|
2022-09-07 18:39:33 +05:00
|
|
|
case ActionTypes.USER_PASSWORD_UPDATE__SUCCESS:
|
|
|
|
if (payload.accessToken) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
accessToken: payload.accessToken,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
2019-08-31 04:07:25 +05:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|