【问题标题】:My web client logs out properly but mobile client does not我的 Web 客户端正确注销,但移动客户端没有
【发布时间】:2016-09-21 15:08:11
【问题描述】:

我在 Node 后端使用 express/express-session/passport,这是我的注销代码。

// GET /logout
exports.logout = (req, res) => {
  req.logout();

  if (req.body.type === "mobile") {
    return res.status(200).json({success: true});
  }

  res.redirect('/');
};

此 Web 应用程序在 http://myapp.dev:3000 上运行。只要我在 Web 应用程序上并单击注销按钮,我就可以毫无问题地登录/注销。

我还有一个在 192.168.2.30:8100 上运行的 Ionic(移动应用程序)。当我在移动应用程序中单击注销按钮时,我会像往常一样向 /logout 发出请求。

$stateProvider.state("auth.signout", {
    url: "/signout",
    controller: "SignoutController",
    resolve: {
        redirect: function($http, $state, Config) {

            $http.get(`${Config.url("/logout")}`, {
                type: "mobile"
            }, {
                withCredentials: true
            }).then(res => {
                $state.go('auth.signin');
            }).catch(res => {
                console.log(res);
                alert("Could not log out");
            });
        }
    }
});

当我单击移动客户端上的注销按钮时,我会返回 JSON,但我无法从移动客户端删除 cookie,因此它会不断重新连接。

知道如何防止这种情况发生吗?

【问题讨论】:

  • 您尝试删除 cookie 时遇到了什么错误?尝试删除时遇到了哪些错误?
  • @VtoCorleone 我该怎么办?告诉 webview 删除 cookie 应该是后端的职责,我相信 req.logout() 为此设置了必要的标题。除了我输入myapp.dev/logout 之外,我的 Web 应用程序没有任何代码,并且可以正常工作。

标签: angularjs node.js ionic-framework


【解决方案1】:

你能展示一下服务器是如何做 Set-Cookie 的吗?

保证你的cookie在客户端被删除有什么问题?

$http.get(`${Config.url("/logout")}`, {
  type: "mobile"
}, {
  withCredentials: true
}).then(res => {
  document.cookie = 'cookieName=;Path=/;Expires=Thu, 01 Jan 1970 00:00:01 GMT;'
  $state.go('auth.signin');
}).catch(res => {
  console.log(res);
  alert("Could not log out");
});

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-15
  • 2020-08-06
  • 1970-01-01
  • 1970-01-01
  • 2017-01-10
  • 1970-01-01
  • 2012-01-03
相关资源
最近更新 更多