diff --git a/app/initializers/custom-session.js b/app/initializers/custom-session.js index a4b66b9..08d48b8 100644 --- a/app/initializers/custom-session.js +++ b/app/initializers/custom-session.js @@ -1,25 +1,11 @@ -import Session from 'simple-auth/session'; -import parseBase64 from '../utils/parse-base64'; import Ember from 'ember'; -var CustomSession = Session.extend({ - currentUser: function() { - let token = this.get('secure.token'); - if (!Ember.isEmpty(token)) { - let t = parseBase64(token); - return this.container.lookup('service:store').find('user', t['sub']); - } - return null; - }.property('secure.token'), - -}); - export function initialize(container, application) { - application.register('session:custom', CustomSession); + application.inject('session:custom', '_store', 'service:store'); } export default { name: 'custom-session', - before: 'simple-auth', + after: 'ember-data', initialize: initialize }; diff --git a/app/sessions/custom.js b/app/sessions/custom.js new file mode 100644 index 0000000..e5a8385 --- /dev/null +++ b/app/sessions/custom.js @@ -0,0 +1,12 @@ +import Session from 'simple-auth/session'; +import parseBase64 from '../utils/parse-base64'; + +export default Session.extend({ + currentUser: function() { + let token = this.get('secure.token'); + if (token && this.get('isAuthenticated')) { + let t = parseBase64(token); + return this._store.findRecord('user', t['sub']); + } + }.property('secure.token', 'isAuthenticated') +});