Advertisement
Guest User

Untitled

a guest
Jun 20th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. Uncaught (in promise) SyntaxError: Unexpected end of input
  2.  
  3. export function loginUser(creds) {
  4.  
  5. let config = {
  6. mode: 'no-cors',
  7. method: 'POST',
  8. headers: { 'Content-Type':'application/x-www-form-urlencoded' },
  9. body: `email=${creds.email}&password=${creds.password}`
  10. };
  11.  
  12.  
  13. return dispatch => {
  14. dispatch(requestLogin(creds));
  15. return fetch('http://localhost:4000/api/authenticate', config)
  16. .then(response =>
  17. response.json()
  18. .then(user => ({ user, response }))
  19. ).then(({ user, response }) => {
  20. if (!response.ok) {
  21. dispatch(loginError(user.message));
  22. return Promise.reject(user);
  23. } else {
  24. localStorage.setItem('id_token', user.token);
  25. dispatch(receiveLogin(user));
  26. }
  27. });
  28. };
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement