我尝试使用Google's official documentation on Github在我的应用上添加Firebase ui auth。
电子邮件登录工作正常,但我遇到了手机登录选项的问题。
点击“使用电话登录”并输入我的号码后输入的6位数代码,我无法注册或登录。
圆形加载圈无休止地旋转,并且不会将我重定向到signInSuccessUrl
中定义的main.js
。
我在控制台中遇到的错误是:
firebaseui.js:82 Uncaught TypeError: Cannot read property 'call' of undefined
at Ca (firebaseui.js:82)
at Fl (firebaseui.js:323)
at firebaseui.js:324
at firebaseui.js:281
at El.<anonymous> (firebaseui.js:238)
at oe (firebaseui.js:140)
at ne (firebaseui.js:139)
at ni (firebaseui.js:219)
at li.h (firebaseui.js:219)
at le (firebaseui.js:136)
Ca @ firebaseui.js:82
Fl @ firebaseui.js:323
(anonymous) @ firebaseui.js:324
(anonymous) @ firebaseui.js:281
(anonymous) @ firebaseui.js:238
oe @ firebaseui.js:140
ne @ firebaseui.js:139
ni @ firebaseui.js:219
li.h @ firebaseui.js:219
le @ firebaseui.js:136
he @ firebaseui.js:137
b @ firebaseui.js:134
我的index.html
<!DOCTYPE html>
<html>
<head>
<title>Site Web flow</title>
<link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/2.6.0/firebaseui.css" />
</head>
<body>
<h1>Site Web flow</h1>
<div id="firebaseui-auth-container"></div>
<hr>
<div>
<div id="loader">Loading...</div>
<div id="sign-in-status"></div>
<div id="sign-in"></div>
<div id="account-details"></div>
<button id="signOutButton">Signout</button>
</div>
<script src="https://cdn.firebase.com/libs/firebaseui/2.6.0/firebaseui.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.1/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.1/firebase-firestore.js"></script>
<script src="main.js"></script>
</body>
</html>
我的main.js文件:
let config = {
apiKey: '##',
authDomain: '##',
projectId: '##'
};
firebase.initializeApp(config);
const db = firebase.firestore();
// const auth = firebase.auth();
let uiConfig = {
signInOptions: [
{
provider: firebase.auth.EmailAuthProvider.PROVIDER_ID,
requireDisplayName: true
},
{
provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID,
defaultCountry: 'IN'
}
],
signInSuccessUrl: './success.html',
tosUrl: '#',
callbacks: {
signInSuccess: (currentUser, credential, redirectUrl) => {
return true;
},
signInFailure: (error) => {
return handleUIError(error);
},
uiShown: () => {
document.getElementById('loader').style.display = 'none';
}
}
};
// Initialize the FirebaseUI Widget using Firebase.
let ui = new firebaseui.auth.AuthUI(firebase.auth());
// The start method will wait until the DOM is loaded.
ui.start('#firebaseui-auth-container', uiConfig);
ui.disableAutoSignIn();
initApp = function() {
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
let displayName = user.displayName;
let email = user.email;
let emailVerified = user.emailVerified;
let photoURL = user.photoURL;
let uid = user.uid;
let phoneNumber = user.phoneNumber;
let providerData = user.providerData;
user.getIdToken().then(function(accessToken) {
document.getElementById('sign-in-status').textContent = 'Signed in';
document.getElementById('sign-in').textContent = 'Sign out';
document.getElementById('account-details').textContent = JSON.stringify({
displayName: displayName,
email: email,
emailVerified: emailVerified,
phoneNumber: phoneNumber,
photoURL: photoURL,
uid: uid,
accessToken: accessToken,
providerData: providerData
}, null, ' ');
});
} else {
// User is signed out.
document.getElementById('sign-in-status').textContent = 'Signed out';
document.getElementById('sign-in').textContent = 'Sign in';
document.getElementById('account-details').textContent = 'null';
}
}, function(error) {
console.log(error);
});
};
window.addEventListener('load', function() {
initApp()
});
document.getElementById('signOutButton').addEventListener('click', (e) => {
e.preventDefault();
firebase.auth().signOut().then(() => {
console.log('Signed out');
})
})
我确实已在Firebase控制台中使用电子邮件和手机启用了登录功能。有人可以帮忙吗?
答案 0 :(得分:3)
更新到最新的firebaseui 2.6.1
npm install firebaseui@2.6.1
OR
npm install firebaseui @ latest
OR npm install firebaseui @ latest --save
答案 1 :(得分:1)
FirebaseUI 2.6.0中的电话号码登录流程中存在错误。 https://github.com/firebase/firebaseui-web/issues/314。我们有一个修复并发布了2.6.1。遇到相同问题的任何人,请将firebaseUI更新到最新版本2.6.1。