Created
April 7, 2017 07:22
-
-
Save riyadhalnur/4ccfd67560017bb580abfdfb8d5bb03c to your computer and use it in GitHub Desktop.
Extend ember-simple-auth-token to check for more information
This file contains hidden or 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
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); }); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI, the file can be placed inside a new folder called
authenticators
inside theapp
folder for an Ember project, i.e.app > authenticators > token.js