【问题标题】:ExpressJs , Node Js , Passport - logout back buttonExpressJs , Node Js , Passport - 注销返回按钮
【发布时间】:2017-08-27 22:02:35
【问题描述】:

我有一个关于后退按钮的问题。众所周知,在按下注销按钮后,如果用户按下后退按钮,则必须将其重定向到登录页面而不是经过身份验证的页面。 我试图找到解决方案,但在我的情况下无法解决。

提前致谢

这是我的 routes.js 截图:

【问题讨论】:

  • 请将您的代码添加为文本,而不是图像。

标签: node.js express button logout back


【解决方案1】:

当用户在浏览器中导航回来时,数据显示在本地浏览器缓存中,而不是从您的服务器请求。

当浏览器返回按钮时使用如下设置,页面被重新加载并且不被缓存。

// caching disabled for every route
server.use(function(req, res, next) {
  res.set('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
  next();
});

// otherwise put the res.set() call into the route-handler you want

【讨论】:

    【解决方案2】:

    你可以使用 ensureLoggedIn

    首先通过 npm install 安装 ensureLoggedIn

         var ensureLoggedIn=require("connect-ensure-login").ensureLoggedIn
          app.get('/profile', ensureLoggedIn('/login'),function(req,res){
            res.sendFile(__dirname +'/public/selflocates.html'); 
            })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      • 2012-05-17
      • 2020-11-21
      • 2020-06-04
      • 2014-10-22
      • 2013-07-20
      • 1970-01-01
      相关资源
      最近更新 更多