Oauth 2.0 Cors阻止不一致oauth2登录

Oauth 2.0 Cors阻止不一致oauth2登录,oauth-2.0,cors,discord,passport.js,nestjs,Oauth 2.0,Cors,Discord,Passport.js,Nestjs,我正在尝试使用discord功能进行注册。流程如下所示: 下一个前端还不存在,所以我用一个基本的html文件来测试它: 文件 不和谐登录 const onClick=async()=>{ const res=等待取数('https://api.league.pr1sm.gg/auth/discord', { 方法:“GET”, 重定向:“跟随”, 标题:{ “访问控制允许来源”:https://api.league.pr1sm.gg', }, }); log('onClick->res->t

我正在尝试使用discord功能进行注册。流程如下所示:

下一个前端还不存在,所以我用一个基本的html文件来测试它:


文件
不和谐登录
const onClick=async()=>{
const res=等待取数('https://api.league.pr1sm.gg/auth/discord', {
方法:“GET”,
重定向:“跟随”,
标题:{
“访问控制允许来源”:https://api.league.pr1sm.gg',
},
});
log('onClick->res->text',wait res.text());
log('onClick->res',wait res);
};

html部署在
https://league.pr1sm.gg
https://api.league.pr1sm.gg

这是我收到的错误:

Access to fetch at 'https://api.league.pr1sm.gg/auth/discord' from origin 'https://league.pr1sm.gg' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.


您需要在应用程序中启用跨源资源共享,才能完成此过程。您可能还需要告诉discord允许哪些回调url进入您的应用程序

要启用CORS,请转到main.ts并添加此

app.enableCors();
有关更多信息,请查看官方文档


我已经这么做了。正如你所写的那样,app.enableCors({origin:'',methods:'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',preflight continue:true,OPTIONS successstatus:200,credentials:true,});