javascript - Passport.authenticate 抛出未经授权的错误 iwith cookie 方法
问题描述
Passport.authenticate 使用 cookie 方法抛出未经授权的错误。哪里可能有问题,在护照 js 设置或前端?有趣的是,在另一个开发人员的编译器上它工作正常
节点JS
router.post('/check',passport.authenticate("cookie", { session: false }), async (req, res, next) => {
try {
return res.status(200).json({ status: true })
} catch (error) {
res.status(400).json(error);
}
});
前端
export async function isAuthorized(context, commands) {
let token = getCookie('token')
if (token) {
let settings = {
"method": 'POST',
headers: {
"Content-Type": "application/json",
},
}
try {
let response = await fetch('/api/auth/check', settings) //here unathorized
let result = await response.json()
return result.status
} catch (error) {
throw Error
}
} else {
return false
}
}
cookie 已成功发送,也许我需要为护照或类似的东西使用一些额外的设置
解决方案
推荐阅读
- python - 使用 Ironclad 在 Iron Python 中实现 Opencv
- python - 从 GitHub (urllib.request) 下载 csv 文件时出错
- linux - x86 中的分段与 linux 下编译器中的分段
- testing - 如何在 Azure DevOps 中运行未完成时更改其状态
- asp.net-core - 尝试激活“XXXXX”时无法解析“Microsoft.AspNetCore.SignalR.Hub`1[IXXXX]”类型的服务
- java - 使用attributeconverter时,SpringBoot应用程序未完成启动
- php - 为什么我的 ionic 应用程序不显示来自 Android 数据库的数据?
- laravel - 如何模拟 Laravel Auth 门面的给定方法
- javascript - 如何使用 ref 在 react.js 中的两个按钮之间切换?
- openssl - 如何将多个答案传递给 shell 命令?