node.js - 会话结束后从用户浏览器中删除 cookie。我使用 Passport-twitter 对用户进行身份验证。
问题描述
您好,我正在构建一个使用 passport-twitter 对用户进行身份验证的应用程序,我能够使用 twitter 凭据成功登录用户,但我希望在我们注销时用户(销毁会话),所以 cookie 也是销毁,所以每次用户回到应用程序时,他都需要再次进行身份验证。所以我猜我的会话必须修改,但我不知道如何。
app.use(session({
secret: "our-passport-local-strategy-app",
resave: true,
saveUninitialized: true
}));
任何帮助表示赞赏
解决方案
尝试使用 Passport 的官方方法进行注销。该request
对象有一个可以使用的装饰器。如果您使用的是 Express.js 4.x,则“结果”对象也有cookie 操作装饰器。
app.get('/logout', function(req, res){
// Destroy the session if any
req.logout();
// Clear the specified cookies
res.clearCookie('your_key');
// Redirect to homepage
res.redirect('/');
});
推荐阅读
- assembly - 我怎样才能知道 101b 在数字中显示了多少次?
- flutter - 为什么我的课程会自动复制到父亲中?
- knockout.js - 自动完成中数据上传的最小符号数量
- apache-kafka-streams - 有没有办法在 Kafka Streams 中实时加入/合并记录?
- java - 创建将保留默认错误控制器功能的错误控制器
- error-handling - “如何知道'服务器是否在线'而不在 socket_connet 中出现 php 错误”
- swift - 直接从 UITabBarController 和通过 UINavigationController 选择 UIViewController
- java - 在java中使用正则表达式将文本文件分成块
- javascript - 从两个对象创建一个对象数组
- c# - 如何将 SelectedItems 发送到 DataRowView 数组?