With ember-data 1.0.0-beta.8, ember-simple-auth loads the current user from my API before making any other requests. This guarantees the current user data will be available in other routes. After upgrading to ember-data 1.0.0-beta.9, it loads the current user after making other API requests.
Is there a way to force ember-simple-auth to load the current user before other data using ember-data 1.0.0-beta.9?
My custom simple auth session that looks like this:
import SimpleAuthSession from 'simple-auth/session';
export default SimpleAuthSession.extend({
updateCurrentUser: function() {
var self = this;
var userId = this.get('user_id');
if (!Ember.isEmpty(userId)) {
self.set('currentUser', self.container.lookup('store:main').find('current-user', userId));
}
}.observes('user_id')
});
My authentication initializer:
import MyAppSession from 'my-app-ember/lib/my-app-session';
import FacebookAuthenticator from 'my-app-ember/lib/facebook-authenticator';
export default {
name: 'authentication',
before: 'simple-auth',
initialize: function(container) {
container.register('session:my-app-session', MyAppSession);
container.register('simple-auth-authenticator:facebook', FacebookAuthenticator);
window.ENV = window.ENV || {};
window.ENV['simple-auth'] = {
session: 'session:my-app-session',
authorizer: 'simple-auth-authorizer:oauth2-bearer',
routeAfterAuthentication: 'moments'
};
window.ENV['simple-auth-oauth2'] = {
serverTokenEndpoint: MyAppEmberENV.API_NAMESPACE + '/oauth/token'
};
}
};
Here's an example of a place where I'm depending on the currentUser object to be set on the session in an afterModel hook and is broken after the upgrade:
export default Ember.Route.extend({
model: function() {
return this.store.find('moment');
},
afterModel: function() {
if (!this.get('session.currentUser.isReturningUser')) {
this.transitionTo('settings');
}
}
});