【发布时间】:2014-07-06 17:55:22
【问题描述】:
我正在使用 Ember CLI 并成功集成了 Simple Auth Addon。不幸的是,我目前面临一个问题,我似乎无法在我的项目的ApplicationRoute 中触发sessionAuthenticationFailed 操作。我已经使用 Ember Simple Auth 的浏览器化版本成功地做到了这一点,但我现在真的很想使用 Ember CLI 的插件并弄清楚这一点!目前我的 ApplicationRoute 在 Coffescript 中看起来像这样:
`import Ember from 'ember'`
`import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin'`
`import Session from 'simple-auth/session'`
ApplicationRoute = Ember.Route.extend ApplicationRouteMixin,
actions:
sessionAuthenticationFailed: (error) ->
debugger
`export default ApplicationRoute`
我还尝试重新打开 ApplicationRouteMixin 并在函数中设置debugger,这也不起作用。据我所知,Ember Simple Auth 的源代码Session 通过在其authenticate 函数中调用_this.trigger('sessionAuthenticationFailed', error) 来触发事件。我还将工作版本与目前不工作的版本进行了比较,当我在调用触发器后单步执行代码时,我最终进入了接收对象的sendEvent 函数,在这种情况下它是 Ember Simple Auth Session,一个事件名称、参数和操作。这里有趣的是,这部分代码从 Session 中读取了一些关于 listeners 的元数据:
var meta = obj[META_KEY];
actions = meta && meta.listeners && meta.listeners[eventName];
在我的情况下,meta.listeners[eventName] 是 undefined,这意味着 sessionAuthenticationFailed 事件没有侦听器,因此任何事情都不会被调用,我最终无法通过我的操作来捕捉事件。
现在最大的问题当然是为什么它似乎没有为此事件注册任何侦听器。是否有其他人已经在使用 Ember CLI Simple Auth Addon 并成功挂钩 sessionAuthenticationFailed 事件?如果有帮助,将不胜感激!
干杯, 戴夫!
编辑 通过阅读源代码的 cmets,我看到如果在扩展 ApplicationRoute 中使用了 beforeModel 挂钩,我也必须通过 this._super() 调用父级的 beforeModel 函数。我想我离解决这个问题又近了一步!
【问题讨论】:
标签: javascript ember-cli ember-simple-auth