Skip to content

Instantly share code, notes, and snippets.

@lancetw
Created September 24, 2015 04:22
Show Gist options
  • Save lancetw/7bf3dc2bccb567462a4b to your computer and use it in GitHub Desktop.
Save lancetw/7bf3dc2bccb567462a4b to your computer and use it in GitHub Desktop.
export function login (form) {
return async dispatch => {
dispatch({ type: AUTH_USER_STARTED })
try {
const res = await auth(form)
if (res && res.token) {
setToken(res.token)
return dispatch({
type: AUTH_USER_COMPLETED,
token: res.token
})
} else throw new Error('no token')
} catch (err) {
return dispatch({
type: AUTH_USER_FAILED,
errors: err.message
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment