Skip to content

Instantly share code, notes, and snippets.

@Soffcsr
Created July 16, 2020 00:48
Show Gist options
  • Save Soffcsr/8d19d9247c9c7de6fcd5018934834731 to your computer and use it in GitHub Desktop.
Save Soffcsr/8d19d9247c9c7de6fcd5018934834731 to your computer and use it in GitHub Desktop.
import { LOGIN_USER, LOGIN_SUCCESS, LOGIN_ERROR, LOGOUT } from "../constants/action-types"
const initState = {
loged: false,
error: '',
credentials: {
token: '',
username: '',
userlastname: ''
}
}
const authReducer = (state = initState, action) => {
switch(action.type){
case LOGIN_USER :
return {
credentials: action.payload,
loged: true
};
case LOGIN_SUCCESS :
return {
loged: action.payload
};
case LOGIN_ERROR :
return {
loged: false,
error: action.payload.error
};
case LOGOUT :
return {
loged: false
}
default:
break;
}
return state
}
export default authReducer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment