简体   繁体   English

在ember-simple-auth中关闭浏览器关闭会话?

[英]Invalidate a session on browser close in ember-simple-auth?

I'm pretty new to Ember.js and ember-simple-auth , so I hope you can help me. 我对Ember.jsember-simple-auth很新,所以我希望你能帮助我。

I'm using ember-simple-auth in my application. 我在我的应用程序中使用了ember-simple-auth What I want to do is to invalidate the session when the browser is closed or the user leaves the page. 我想要做的是在浏览器关闭或用户离开页面时使会话无效。 This is only supposed to happen if the user previosly logged in (thats why put it in the authenticate action). 只有当用户提前登录时才会发生这种情况(这就是为什么要将其置于身份验证操作中)。

I tried something like this: 我试过这样的事情:

actions: {
    authenticate: function() {
        var _this = this;
        this._super().then(null, function(message) {
            _this.set('errorMessage', message);
        });

         $(window).on('beforeunload',function() {
            _this.get("session").invalidate();
        });
    }
}

The problem is that it does not work when closing the browser. 问题是关闭浏览器时它不起作用。 Also when I change the URL (to leave the application, for example www.google.com ) it transitions to "/" and does not open the desired URL. 此外,当我更改URL(离开应用程序,例如www.google.com )时,它会转换为“/”并且不会打开所需的URL。

So the question is: How do I invalidate the session when the browser closes (or when the user leaves the application). 所以问题是:当浏览器关闭时(或用户离开应用程序时),如何使会话无效。

Thanks. 谢谢。

I'm not sure how you would handle the case when the user leaves the application (you can probably handle some navigation event and the invalidate the session with this.get("session").invalidate(); ). 我不确定当用户离开应用程序时你将如何处理这种情况(你可以处理一些导航事件并使用this.get("session").invalidate(); )。 To invalidate the session when the user closes the browser though, the best solution is to use the cookie session store and configure a sessionExpirationTime of null so that the cookies are session cookies that get deleted automatically when the browser is closed. 要在用户关闭浏览器时使会话无效,最佳解决方案是使用cookie会话存储并将sessionExpirationTime配置为null以便cookie是在浏览器关闭时自动删除的会话cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM