I'm trying to get the 'session.current_user' object accessible in all routes and controllers. It should be accessible as a promise, so I can prefilter models from the controllers. But I can't seem to get the promise chain working correctly.
I have this in the authentication initializer of ember-simple-auth
Ember.Application.initializer
name: 'authentication',
initialize: (container, application) ->
Ember.SimpleAuth.Authenticators.OAuth2.reopen
serverTokenEndpoint: '/oauth/token'
Ember.SimpleAuth.Session.reopen
+computed
current_user: ->
Ember.run ->
Ember.$.get('/api/v1/credentials/me').then (response) ->
container.lookup('store:main').find('user', response.user.id)
And this in the application controller:
class App.ApplicationController extends Ember.Controller
+computed session.current_user
current_user_gravatar_url: ->
@get('session.current_user').then (current_user) ->
# but I get this here
Em.inspect(current_user)
# => "<DS.PromiseObject:ember656>"
# 'http://www.gravatar.com/avatar/' + md5(current_user.get('email'))
The request to users model comes AFTER the application controller actions.
XHR finished loading: "http://localhost:3000/api/v1/users/3".
What am I doing wrong here? Is the nesting too deep or should I somehow split the 'current_user' computed property into separate dependent computed properties>