Last active
March 27, 2017 07:57
-
-
Save sankalpsingha/ab0e90091c67434c0fbbc69c185d1a51 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
/*global fetch:false*/ | |
export const emailChanged = (email) => { | |
return { | |
type: 'EMAIL_CHANGED', | |
payload: email | |
}; | |
}; | |
export const passwordChanged = (password) => { | |
return { | |
type: 'PASSWORD_CHANGED', | |
payload: password | |
}; | |
}; | |
export const loginUser = ({ email, password }) => { | |
return (dispatch) => { | |
dispatch({ | |
type: 'LOAD_SPINNER' | |
}); | |
fetch('http://localhost:3000/token', { | |
method: 'POST', | |
headers: { | |
Accept: 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
user: { | |
email, | |
password, | |
} | |
}) | |
}).then((response) => { | |
console.log(response); | |
if (response.status === 401) { | |
console.log('AUTHENTICATION ERROR!!'); | |
dispatch({ | |
type: 'LOGIN_FAILED' | |
}); | |
} else { | |
console.log('SUCCESS!!'); | |
response.json().then(data => { | |
console.log(data); | |
dispatch({ | |
type: 'LOGIN_USER_SUCCESS', | |
payload: data | |
}); | |
}); | |
} | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment