Created
October 20, 2017 14:05
-
-
Save diego3g/c4e22ab3f76e73107152647895e355ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store/ducks/auth.js | |
// Action Types | |
export const Types = { | |
LOGIN: 'auth/LOGIN', | |
LOGOUT: 'auth/LOGOUT', | |
}; | |
// Reducer | |
const initialState = { | |
isLogged: false, | |
token: null, | |
user: {}, | |
}; | |
export default function reducer(state = initialState, action) { | |
switch (action.type) { | |
case Types.LOGIN: | |
return {...}; | |
case Types.LOGOUT: | |
return {...}; | |
default: | |
return state; | |
} | |
} | |
// Action Creators | |
export function login(username, password) { | |
return { | |
type: Types.LOGIN, | |
payload: { | |
username, | |
password | |
}, | |
} | |
} | |
export function logout() { | |
return { | |
type: Types.LOGOUT, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment