我使用Meteor默认的账号密码包。 用户登录数据(loginToken、userId和loginTokenExpires)存储在localStorage中,因此当我关闭浏览器时用户仍然处于登录状态。如何防止这种情况?是否可以将用户数据存储在sessionStorage中?
最佳答案
试试这个:
Accounts.config({loginExpirationInDays: 0});
文档 http://docs.meteor.com/#/full/accounts_config说(我自己没有尝试过,但听起来应该可行):
The number of days from when a user logs in until their token expires and they are logged out. Defaults to 90. Set to null to disable login expiration.
更新的答案: 您可以在浏览器即将关闭时清理本地存储,如下所示:
Template.body.rendered = function () {
$(window).on('beforeunload', function () {
// You can either remove the login tokens manually from localstorage like this:
// localStorage.removeItem(key);
// Alternatively you should be able to log out Meteor here (not tested), eg:
// Meteor.logout();
});
};
关于meteor - 如何在 Meteor 中保持用户登录直到浏览器关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27282158/