So I have a simple ESA setup with a custom authenticator/authorizer wrapping Basic HTTP Auth. The login route uses UnauthenticatedRouteMixin
and the login controller is basically just authenticating against the custom authenticator, and afterwards fetches the user object from a REST service:
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
login() {
var self = this;
let { userName, password } = this.getProperties('userName', 'password');
this.get('session').authenticate('authenticator:basicauth', userName, password).then(function ()
{
self.store.queryRecord('user', { loginname : userName }).then( function (user) {
console.log(user.get('id'));
self.get('session').set('data.filterUserId', user.get('id'));
});
}).catch((reason) => {
this.set('errorMessage', reason.error || reason);
});
}
}
});
Now, in the first authenticated route (via AuthenticatedRouteMixin
), for testing I also simply console.log the stored session property:
import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
session: Ember.inject.service('session'),
model: function () {
console.log(this.get('session.data.filterUserId'));
},
});
In the console output, I observe that the model hook seems to be executed before the authenticator's promise is resolved, i.e. first I get "null", then the ID.
How can I make the AuthenticatedRoute wait for the actual login authentication to resolve?