【发布时间】:2021-08-22 20:46:12
【问题描述】:
我有一个在 vercel 上部署的 nextjs 应用程序。它与部署在heroku中的nestjs后端配对。
我通过 github 实现了登录,在开发应用程序时,我使用以下代码在用户成功通过身份验证后设置了 jwt 标头:
@Get('redirect')
@UseGuards(AuthGuard('github'))
async githubAuthRedirect(@Req() req, @Res() res) {
const accessToken = await this.authService.generateJWT(req.user);
res.cookie('jwt', accessToken);
res.redirect(`http://localhost:3000/dashboard`);
}
这是一旦用户批准访问其帐户后,github 调用的端点。
当我在 localhost 上运行所有内容时,它可以工作,但是一旦我将前端应用程序部署到 vercel,将后端应用程序部署到 heroku(并为我的 api 配置了 CNAME 别名),它就不起作用了。
我的服务器从 github 获取请求,用户被有效地重定向到仪表板,但没有设置 cookie。
我做错了吗?我错过了一些 vercel/nextjs 配置吗?
【问题讨论】:
标签: heroku next.js nestjs vercel