2016-09-21 55 views
0

我在节点后端使用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('/'); 
}; 

此网页应用程序在http://myapp.dev:3000上运行。只要我在Web应用程序上并单击注销按钮,我就可以登录/注销,而不会出现任何问题。

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

$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,因此不断重新连接。

任何想法如何防止这种情况?

+0

您尝试删除您的cookie以及尝试删除它时出现了哪些错误? – VtoCorleone

+0

@VtoCorleone我该怎么做?它应该是后端的责任,告诉webview删除cookies,我相信'req.logout()'设置必要的标题。除了输入'myapp.dev/logout'外,我的web应用程序没有代码,并且工作正常。 – Aris

回答

0

你能展示服务器如何做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"); 
}); 
+0

它基本上是与护照模块一起的快速会话。它看起来像这样:https://github.com/passport/express-4.x-local-example/blob/master/server.js document.cookie在Android/Cordova上始终为null。我猜APK APK缓存在其他地方像应用程序缓存的cookie? – Aris