Skip to content

Instantly share code, notes, and snippets.

@marcoow
Created January 20, 2014 19:06
Show Gist options
  • Save marcoow/8526909 to your computer and use it in GitHub Desktop.
Save marcoow/8526909 to your computer and use it in GitHub Desktop.
Ember.Application.initializer({
name: 'authentication',
initialize: function(container, application) {
// customize the session so that it allows access to the account object
Ember.SimpleAuth.Session.reopen({
account: function() {
var accountId = this.get('account_id');
if (!Ember.isEmpty(accountId)) {
return container.lookup('store:main').find('account', accountId);
}
}.property('accountId')
});
Ember.SimpleAuth.setup(application);
}
});
App.ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin, {
actions: {
sessionAuthenticationSucceeded: function() {
var _this = this;
Ember.$.get('/accounts/me').then(function(response) {
Ember.run(function() {
_this.set('session.account_id', response.id);
});
});
},
sessionInvalidationSucceeded: function() {
this.set('session.account_id', null);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment