meteor - 如何在 Meteor 中保持用户登录直到浏览器关闭?

标签 meteor

我使用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/

相关文章:

html - flex 盒子不工作

javascript - Meteor 中的 ExecCommand 不起作用

javascript - 如何在 meteor 中使用 javaScript 将字符串放入粘贴缓冲区中?

meteor - 我可以通过 __meteor_bootstrap__.app 挂载另一个路由处理程序吗?

javascript - 检测 meteor 中的音隙

javascript - 前端的 Meteor,后端的 Express (NodeJS)

javascript - 如何向 anti :modals in Meteor 添加帮助函数

javascript - jQuery UI draggabe 未定义

javascript - 如何删除mongodb数组中的元素

javascript - Meteor 1.1 - 当特定元素在 dom 上呈现时的回调