ember-simple-auth:任何从路由器内部获取会话的方法



我想使用分析跟踪每个过渡,就像在Mixpanel中提到的EmberJS

为了做到这一点,我需要能够重新打开Router .

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

编辑:

我现在正在探索的另一种方法是在我想要进行分析识别的所有路由上包含一个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)

你可以使用

从Ember的容器中获取会话
container.lookup('simple-auth-session:main');

最新更新