2022-01-10 14:17:52 -08:00
|
|
|
import {
|
|
|
|
AUTH_LOGGED_OUT,
|
|
|
|
AUTH_ACCOUNT_REMEMBER_SUCCESS,
|
|
|
|
VERIFY_CREDENTIALS_SUCCESS,
|
|
|
|
} from '../actions/auth';
|
2020-06-16 15:36:49 -07:00
|
|
|
import {
|
|
|
|
ME_FETCH_SUCCESS,
|
|
|
|
ME_FETCH_FAIL,
|
|
|
|
ME_FETCH_SKIP,
|
|
|
|
ME_PATCH_SUCCESS,
|
|
|
|
} from '../actions/me';
|
2020-04-01 19:20:47 -07:00
|
|
|
|
2020-04-02 12:28:19 -07:00
|
|
|
const initialState = null;
|
2020-04-01 19:20:47 -07:00
|
|
|
|
2021-10-20 15:50:35 -07:00
|
|
|
const handleForbidden = (state, error) => {
|
|
|
|
if (error.response && [401, 403].includes(error.response.status)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-01 19:20:47 -07:00
|
|
|
export default function me(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case ME_FETCH_SUCCESS:
|
2020-06-16 15:36:49 -07:00
|
|
|
case ME_PATCH_SUCCESS:
|
2020-04-17 14:10:55 -07:00
|
|
|
return action.me.id;
|
2021-03-23 22:05:06 -07:00
|
|
|
case VERIFY_CREDENTIALS_SUCCESS:
|
2021-10-20 14:27:36 -07:00
|
|
|
case AUTH_ACCOUNT_REMEMBER_SUCCESS:
|
2021-03-23 22:05:06 -07:00
|
|
|
return state || action.account.id;
|
2020-04-11 16:55:07 -07:00
|
|
|
case ME_FETCH_SKIP:
|
2020-04-11 12:41:13 -07:00
|
|
|
case AUTH_LOGGED_OUT:
|
|
|
|
return false;
|
2021-10-20 14:27:36 -07:00
|
|
|
case ME_FETCH_FAIL:
|
2021-10-20 15:50:35 -07:00
|
|
|
return handleForbidden(state, action.error);
|
2020-04-01 19:20:47 -07:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|