bruno/renderer/providers/Auth/reducer.js

43 lines
1004 B
JavaScript
Raw Normal View History

2022-03-07 15:32:39 +01:00
import produce from 'immer';
const reducer = (state, action) => {
switch (action.type) {
case 'WHOAMI_SUCCESS': {
return produce(state, (draft) => {
draft.isLoading = false;
draft.currentUser = action.user;
draft.lastStateTransition = 'WHOAMI_SUCCESS';
});
}
case 'WHOAMI_ERROR': {
return produce(state, (draft) => {
draft.isLoading = false;
draft.currentUser = null;
draft.lastStateTransition = 'WHOAMI_ERROR';
});
}
case 'LOGIN_SUCCESS': {
return produce(state, (draft) => {
draft.isLoading = false;
draft.currentUser = action.user;
draft.lastStateTransition = 'LOGIN_SUCCESS';
});
}
case 'LOGOUT_SUCCESS': {
return produce(state, (draft) => {
draft.isLoading = false;
draft.currentUser = null;
draft.lastStateTransition = 'LOGOUT_SUCCESS';
});
}
default: {
return state;
}
}
};
export default reducer;