NextAuth Google 提供商无法在 Safari 上运行
Google提供商在Chrome和其他浏览器上工作得很好,但无法在Safari上工作。我似乎在这里的文档中找不到任何相关的内容。
这就是在[... NextAuth]中声明我的提供商的方式。JS
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import GoogleProvider from "next-auth/providers/google";
import FacebookProvider from "next-auth/providers/facebook";
export default NextAuth({
debug: true,
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
state: false,
authorizationUrl:
'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code',
}), ...
在Safari上与Google登录的函数
async function signInWithGoogle() {
const res: any = await signIn("google");
if (res && res.error) {
setErrorMsg(res.error);
setShowError(true);
} else if(!res) {
router.push("/account-error")
}
else {
router.push("/somepage");
}
}
res对象始终不确定。我可以在控制台日志中看到Next Auth能够在 [next-auth] [debug] [get_authorization_url] 中生成有效的授权URL,但是该应用程序不仅不会在Safari上重定向。
The google provider works perfectly fine on Chrome and other browsers but fails to work on Safari. I can't seem to find anything relevant in the documentation here.
This is how my provider is declared in [...nextauth].js
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import GoogleProvider from "next-auth/providers/google";
import FacebookProvider from "next-auth/providers/facebook";
export default NextAuth({
debug: true,
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
state: false,
authorizationUrl:
'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code',
}), ...
The function calling sign in with Google
async function signInWithGoogle() {
const res: any = await signIn("google");
if (res && res.error) {
setErrorMsg(res.error);
setShowError(true);
} else if(!res) {
router.push("/account-error")
}
else {
router.push("/somepage");
}
}
On safari the res object is always undefined. I can see in the console logs that next auth is able to generate a valid authorization URL in [next-auth][debug][GET_AUTHORIZATION_URL] but the app wouldn't redirect on Safari only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果在 Safari 上,下一个身份验证并没有解决承诺。我删除了检查资源的代码,它工作得很好。它被重定向而没有完成使用谷歌登录的请求。让它留在这里,以防有人遇到这个问题。
所以你的函数调用应该是
Turns out on Safari next auth was not resolving the promise. I removed the code where I checked for res and it worked fine. It was being redirected without the request getting completed to sign in with google. Letting it stay here in case any one gets this issue.
So your function call should just be