Skip to content

Instantly share code, notes, and snippets.

@andrewjmead
Last active January 26, 2016 13:54
Show Gist options
  • Save andrewjmead/58454bad04e0b45c2fe7 to your computer and use it in GitHub Desktop.
Save andrewjmead/58454bad04e0b45c2fe7 to your computer and use it in GitHub Desktop.
Marcus - Updated to include headers
// 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
};
})
})
// 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