I am using ember-cli-simple-auth-token which works for initial login auth but not subsequent API requests. To resolve I am working towards setting the token after authenticate and adding the token in RESTAdapter as below.
Token:
{"token":"12345abc"}
Application Adapter:
export default DS.RESTAdapter.extend({
session: Ember.inject.service('session'),
host: 'http://127.0.0.1:8000',
headers: Ember.computed('session.data.token', function() {
var session = this.get('session');
return {
Authorization: "Token " + session.get("data.token")
};
})
});
Authenticate looks like this so far:
authenticate() {
var credentials = this.getProperties('identification', 'password');
var authenticator = 'simple-auth-authenticator:token';
return this.get('session').authenticate(authenticator, credentials).then(() => {
var userToken = '4c00b675868eb53c605cb64281b356ace8795c5b'; // TO DO
this.get('session').set('data.token', userToken);
this.transitionToRoute('dashboard');
}, () => {
return true;
});
},
Any ideas on how I can set the userToken var from the response/promise value or alternatives to achieve this?
Aucun commentaire:
Enregistrer un commentaire