Last active
January 26, 2016 13:54
-
-
Save andrewjmead/58454bad04e0b45c2fe7 to your computer and use it in GitHub Desktop.
Marcus - Updated to include headers
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
// Only part of file | |
return fetch(url, { | |
method: 'post', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json', | |
'Auth': localStorage.getItem('token') | |
}, | |
body: JSON.stringify({ | |
email: userEmail, | |
password: userPassword, | |
}) | |
}).then(function(response) { | |
return response.json().then(function(data) { | |
return { | |
response: response, | |
data: data | |
}; | |
}) | |
}) |
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
// Entire file | |
var Api = require('../utils/api'); | |
var Reflux = require('reflux'); | |
var Actions = require('../actions'); | |
module.exports = Reflux.createStore({ | |
listenables: [Actions], | |
createUser: function(url, userEmail, userPassword) { | |
Api.postUser(url, userEmail, userPassword).then(function(res) { | |
return alert("User Created!" + res.data); | |
}, function() { | |
return alert("Error creating user"); | |
}); | |
}, | |
loginUser: function(url, userEmail, userPassword) { | |
Api.postUser(url, userEmail, userPassword).then(function(res) { | |
var token = res.response.headers.get('Auth') | |
localStorage.setItem('token', token); | |
return alert("User logged in!" + res.data); | |
}, function() { | |
return alert("Cannot login in user"); | |
}); | |
}, | |
triggerChange: function() { | |
this.trigger('change', this.newUser); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment