Skip to content

Instantly share code, notes, and snippets.

@straydogstudio
Last active September 11, 2015 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save straydogstudio/b81406fb8ca29e12f95a to your computer and use it in GitHub Desktop.
Save straydogstudio/b81406fb8ca29e12f95a to your computer and use it in GitHub Desktop.
import Ember from "ember";
// This is an error. It should be 'ember-simple-auth/authenticators/base'
// Left to link to a github comment
import Base from 'ember-simple-auth/authorizers/base';
export default Base.extend({
tokenEndpoint: '/api/user_sessions',
authenticate: function(credentials) {
var _this = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
Ember.$.ajax({
url: _this.tokenEndpoint,
type: 'POST',
data: JSON.stringify({
username: credentials.identification,
password: credentials.password
}),
contentType: 'application/json'
}).then(function(response) {
Ember.run(function() {
resolve({ token: response.token });
});
}, function(xhr) {
var response = JSON.parse(xhr.responseText);
Ember.run(function() {
reject(response.error);
});
});
});
},
restore: function(data) {
return new Ember.RSVP.Promise(function (resolve, reject) {
resolve(data);
});
},
invalidate: function(data) {
return new Ember.RSVP.Promise(function (resolve, reject) {
resolve();
});
},
// on: function(event, callback) {
// console.log('on');
// console.log(callback.toString());
// },
// off: function() {}
});
@straydogstudio
Copy link
Author

Note, this is in error. It should be extended from "ember-simple-auth/authenticators/base" not "ember-simple-auth/authorizers/base".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment