【发布时间】:2014-08-30 22:21:43
【问题描述】:
我想在 Mixpanel with EmberJS 中提到的每个转换中使用分析跟踪
为此,我需要能够重新打开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)
【问题讨论】:
标签: ember.js ember-simple-auth