3

我想在使用EmberJS 的 Mixpanel中提到的每个转换上使用分析跟踪

为此,我需要能够重新打开Router.

有什么办法可以ember-simple-auth在那里获得当前会话?我的理解是它对所有路由和控制器都可用,但没有特别提到路由器。

编辑

我现在正在探索的另一种方法是在我想要进行分析识别的所有路由上包含一个 mixin。我有一个如下的mixin:

`import Ember from 'ember'`

AnalyticsMixin = Ember.Mixin.create
  beforeModel: (transition) ->
    @_super(transition)
    userId = @get('session.user_id')
    if (!Ember.isEmpty(userId))
      user = @store.find('user', userId)
      username = user.get('username') # this doesn't work

我可以user_id从会话对象中获取 ,尽管Session.reopen我所做的似乎并没有单独包含user。也不行@store.find('user', userId)

以下在模板中可以正常工作:

Authentication =
  name: "authentication"
  before: "simple-auth"
  initialize: (container) ->
    Session.reopen
      user: (->
        userId = @get('user_id')
        if (!Ember.isEmpty(userId))
          return container.lookup('store:main').find('user', userId)
      ).property('userId')
    container.register("authenticator:custom", CustomAuthenticator)
4

1 回答 1

2

You can always get the session from Ember's container with

container.lookup('simple-auth-session:main');
于 2014-07-09T19:09:43.513 回答