我正在使用 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 并在函数中设置一个调试器
,但这也不起作用。据我所知,Ember Simple Auth 的源代码 Session
通过在其 authenticate 中调用
函数。我还将工作版本与目前不工作的版本进行了比较,当我在调用触发器后单步执行代码时,我最终进入了接收对象的 _this.trigger('sessionAuthenticationFailed', error)
来触发事件sendEvent
函数,在本例中它是 Ember Simple Auth Session
、一个 eventName、参数和操作。这里有趣的是,在这部分代码中,从 Session 中读取了有关监听器的一些元数据:
var meta = obj[META_KEY];
actions = meta && meta.listeners && meta.listeners[eventName];
在我的例子中,meta.listeners[eventName]
是未定义
,这意味着没有 sessionAuthenticationFailed
事件的监听器,因此不会调用任何内容任何事情,我最终都无法用我的行动捕捉到事件。
现在最大的问题当然是为什么它似乎没有为此事件注册任何监听器。是否有其他人已经在使用 Ember CLI Simple Auth Addon 并成功 Hook sessionAuthenticationFailed
事件?如果是这样,我们将不胜感激!
干杯, 戴夫!
编辑 通过阅读源代码的注释,我发现如果在扩展 ApplicationRoute 中使用 beforeModel 钩子(Hook),我也必须通过 this._super() 调用父级的 beforeModel 函数。我想我离解决这个问题又近了一步!
最佳答案
好的,我解决了这个问题。因此,我在 ApplicationRoute
中实现了 beforeModel(transition)
Hook 来加载翻译,但没有使用 this._super(transition)
调用父函数>。如果您遇到与我描述的相同的问题,这可能是它不起作用的原因之一!
关于javascript - 操作不是由 Ember CLI 简单例份验证 ApplicationRouteMixin 触发的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24598667/