Skip to content

Instantly share code, notes, and snippets.

@riyadhalnur
Created April 7, 2017 07:22
Show Gist options
  • Save riyadhalnur/4ccfd67560017bb580abfdfb8d5bb03c to your computer and use it in GitHub Desktop.
Save riyadhalnur/4ccfd67560017bb580abfdfb8d5bb03c to your computer and use it in GitHub Desktop.
Extend ember-simple-auth-token to check for more information
import Ember from 'ember';
import Base from 'ember-simple-auth-token/authenticators/token';
export default Base.extend({
authenticate(credentials, headers) {
return new Ember.RSVP.Promise((resolve, reject) => {
const data = this.getAuthenticateData(credentials);
this.makeRequest(data, headers).then(response => {
if (response.data && response.data.role === 'admin') {
Ember.run(() => {
resolve(this.getResponseData(response));
});
} else {
Ember.run(() => { reject(new Error('Unauthorised!')); });
}
}, xhr => {
Ember.run(() => { reject(xhr.responseJSON || xhr.responseText); });
});
});
}
});
@riyadhalnur
Copy link
Author

FYI, the file can be placed inside a new folder called authenticators inside the app folder for an Ember project, i.e. app > authenticators > token.js

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