我正在尝试在一个简单的HTML页面上实现基本的Google登录,但由于某种原因它无法工作,并给我显示标题中的错误。这只是在Firebase文档中可以找到的基本弹出式登录功能,我有一个按钮
<button class="w-100 btn btn-lg btn-success" id="g_sign" onclick="signInWithPopup">使用Google登录</button>
这是一个带有onclick属性的基本Bootstrap按钮,用于调用signinwithpopup
const auth = getAuth();
signInWithPopup(auth, provider)
.then((result) => {
// 这将给你一个Google访问令牌。你可以用它来访问Google API。
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
// 登录用户信息。
const user = result.user;
// 使用getAdditionalUserInfo(result)可以获取IdP数据
// ...
}).catch((error) => {
// 处理错误。
const errorCode = error.code;
const errorMessage = error.message;
// 使用的用户帐户的电子邮件。
const email = error.customData.email;
// 使用的AuthCredential类型。
const credential = GoogleAuthProvider.credentialFromError(error);
// ...
});
我尝试在auth常量中添加const app,但没有任何作用,希望有人能帮忙!
const auth = getAuth(app);
我尝试使用Firebase身份验证添加Google身份验证提供程序,所以我按照文档说明进行操作,并期望看到一个简单的弹出式窗口询问我要使用哪个Google帐户,但它没有这样做,而是在控制台中抛出了一个错误。我还查看了其他人在这里提出的问题的解决方案,但似乎没有一个解决方案起作用。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我认为,这是因为你使用了onclick,而应该使用首字母大写的onClick。