Skip to content

Instantly share code, notes, and snippets.

@bfcoder
Created May 22, 2015 15:52
Show Gist options
  • Save bfcoder/ebfa3c64cabfed9c26fb to your computer and use it in GitHub Desktop.
Save bfcoder/ebfa3c64cabfed9c26fb to your computer and use it in GitHub Desktop.
Ember 1.12 current_user initializer
Ember.Application.initializer({
name: 'currentUser',
initialize: function(registry, application) {
// Register the `user:current` namespace
application.register("user:current", App.CurrentUserController, { singleton: true });
// Inject the namespace into controllers and routes
application.inject('route', 'currentUser', "user:current");
application.inject('controller', 'currentUser', "user:current");
}
});
Ember.Application.instanceInitializer({
name: 'currentUser',
initialize: function(instance) {
return instance.container.lookup('store:main').find('user', 'current_user').then( function(user) {
var currentUser = instance.container.lookup("user:current");
currentUser.set('model', user);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment