This commit is contained in:
Ahmed Bouhuolia
2020-03-16 00:06:15 +02:00
parent 56701951b7
commit 73711384f6
7925 changed files with 18478 additions and 959 deletions

View File

@@ -0,0 +1,34 @@
import {createReducer} from '@reduxjs/toolkit';
import t from 'store/types';
const initialState = {
token: '',
user: '',
locale: '',
errors: [],
};
export default createReducer(initialState, {
[t.LOGIN_SUCCESS]: (state, action) => {
state.token = action.token;
state.user = action.user;
},
[t.LOGIN_FAILURE]: (state, action) => {
state.errors = action.errors;
},
[t.LOGOUT]: (state) => {
state.token = '';
state.user = {};
},
[t.LOGIN_CLEAR_ERRORS]: (state) => {
state.errors = [];
},
});
export const isAuthenticated = (state) => !!state.authentication.token;
export const hasErrorType = (state, errorType) => {
return state.authentication.errors.find(e => e.type === errorType);
};