I am building react + redux + reactRouter app. I have an api which sends me tokens after login, so I can protect my api, but I have front-end routes, that should be protected (like dashboard).
I have login form which dispatches login action.
.../actions/loginAction.js
axios.post('/api/auth', {
email: email,
password: password
}).then(function (response) {
dispatch({
type: response.data.token ? types.LOGIN_SUCCESS : LOGIN_FAILED,
email: email
});
}).catch(function (error) {
dispatch({
type: LOGIN_FAILED,
error: error
});
});
and the reducer
import * as types from '../actions/actionTypes';
let initialState = {
email: '',
isAuthenticated: false,
authenticating: false,
authError: false
};
export default (state = initialState, action) => {
switch (action.type){
case types.LOGIN_START:
return Object.assign({}, state, {authenticating: true});
case types.LOGIN_FAILED:
return Object.assign({}, state, {authenticating: false, isAuthenticated: false, authError: action.error});
case types.LOGIN_SUCCESS:
return Object.assign({}, state, {
authenticating: false,
isAuthenticated: true,
authError: false,
email: action.email
});
default:
return state;
}
};
It WORKS, BUT anyone can hack it, just editing value of redux store from console, or dispatching LOGIN_SUCCESS action, or even editing js where is verification, is it right? How to avoid it?