[英]“Ember Simple Auth” invalidateSession from component
Trying to execute this code within a component's template 尝试在组件模板中执行此代码
// components/my-component.js
{{#if session.isAuthenticated}}
<a {{action 'invalidateSession'}}>Sign out</a>
{{else}}
{{#link-to 'signin'}}Sign in{{/link-to}}
{{/if}}
However, when clicking "Sign out" button I get this error 但是,单击“退出”按钮时出现此错误
Error: <...@component:my-component::ember381> had no action handler for: invalidateSession
How do I make "invalidateSession" available from a component? 如何使“ invalidateSession”可从组件使用?
You can just implement your own invalidateSession
action: 您可以只实现自己的invalidateSession
操作:
actions: {
invalidateSession: function() {
this.get('session').invalidate();
}
}
or simply forward the action from the component to the route: 或简单地将操作从组件转发到路线:
{{my-component invalidateSession='invalidateSession'}}
You need to add the Simple Auth ApplicationRouteMixin
to your ApplicationRoute
. 您需要将简单身份验证ApplicationRouteMixin
添加到您的ApplicationRoute
。 For example if you are using ES6 modules do 例如,如果您使用的是ES6模块,
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
ApplicationRoute = Ember.Route.extend ApplicationRouteMixin,
The action should bubble up to the application route, where it will be handled. 该操作应冒泡到将在其中进行处理的应用程序路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.