【发布时间】:2021-05-10 19:05:04
【问题描述】:
Google 登录可以在我的本地计算机上运行,但在我部署到 Heroku 时却不行。我已经更新了我的 API 控制台以包含 heroku 主机。我在 Heroku 上使用免费计划。我的感觉是按钮点击甚至没有在 API 上注册 - 我没有收到任何错误或任何东西。
客户端代码:
<Button
fullWidth
variant="contained"
color="primary"
className={classes.submit}
href={
process.env.NODE_ENV === "production"
? `${window.location.origin}/api/google-sign-in`
: "http://localhost:5000/api/google-sign-in"
}
>
Google Sign In
</Button>
服务器代码:
googleSignIn = async (req: Request, res: Response, next: NextFunction) => {
console.log("Google sign in");
try {
const errors = {};
// Generate an OAuth URL and redirect there
const url = await this.oAuth2Client.generateAuthUrl({
scope: [
"profile",
"email",
"https://www.googleapis.com/auth/drive.file",
],
access_type: "offline",
});
// Get url
if (url) {
res.redirect(url);
} else {
res.redirect("/login");
}
} catch (e) {
next(e);
}
};
以前有人遇到过这个问题吗?
【问题讨论】:
标签: node.js reactjs heroku web-applications google-signin