【发布时间】:2021-12-30 19:06:24
【问题描述】:
在API 中使用"{withCredentials:true}" 时出现以下错误。如果我不使用它,则它不起作用。
const submit = async(e:SyntheticEvent) =>{
e.preventDefault();
await axios.post('http://localhost:8000/api/login',{
email,
password
});
}
以上工作正常。当我使用{withCredentials:true} 时,它会给出cors() 错误。
const submit = async(e:SyntheticEvent) =>{
e.preventDefault();
await axios.post('http://localhost:8000/api/login',{
email,
password
},{withCredentials:true});
setRedirect(true);
}
在main.ts 文件中我有以下配置。
const options = {
origin: '*',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
preflightContinue: false,
credentials: true,
};
app.enableCors(options);
即使我尝试了credentials: false, 仍然无法正常工作。
我必须使用{withCredentials:true},以便我可以使用jwt tokens 进行授权。
【问题讨论】:
-
您不能同时使用
credentials: true和origin: *。请参阅上面的注释developer.mozilla.org/en-US/docs/Web/HTTP/…
标签: node.js reactjs cors nestjs nestjs-config