Firebase登录不起作用
在完成教程的“用户登录”部分后,我确保选中“”,以查看我的登录功能是否正常。我做了“阅读消息”部分,现在我没有看到任何登录 我也看不到我导入的任何消息。。。 FriendlyChat.prototype.initFirebase=函数(){ //Firebase SDK功能的快捷方式。 this.auth=firebase.auth(); this.database=firebase.database(); this.storage=firebase.storage(); //启动Firebase身份验证并侦听身份验证状态更改。 this.auth.onAuthStateChanged(this.onAuthStateChanged.bind(this)); //TODO(开发人员):初始化Firebase。 }; 这些是我必须改变的功能。我可以做些什么来覆盖我以前正确的登录实现,并且不访问我导入的数据库消息 在github上进行讨论可能会有所帮助:Firebase登录不起作用,firebase,Firebase,在完成教程的“用户登录”部分后,我确保选中“”,以查看我的登录功能是否正常。我做了“阅读消息”部分,现在我没有看到任何登录 我也看不到我导入的任何消息。。。 FriendlyChat.prototype.initFirebase=函数(){ //Firebase SDK功能的快捷方式。 this.auth=firebase.auth(); this.database=firebase.database(); this.storage=firebase.storage(); //启动Firebas
如果与登录相关的
和
中的“代码控制隐藏”属性无法运行,则默认情况下登录代码将隐藏。您可以随时对照包含codelab已完成工作代码的文件夹检查代码
特别是您是否有:
// Sets up shortcuts to Firebase features and initiate firebase auth.
FriendlyChat.prototype.initFirebase = function() {
// Shortcuts to Firebase SDK features.
this.auth = firebase.auth();
this.database = firebase.database();
this.storage = firebase.storage();
// Initiates Firebase auth and listen to auth state changes.
this.auth.onAuthStateChanged(this.onAuthStateChanged.bind(this));
};
而且:
// Triggers when the auth state change for instance when the user signs-in or signs-out.
FriendlyChat.prototype.onAuthStateChanged = function(user) {
if (user) { // User is signed in!
// Get profile pic and user's name from the Firebase user object.
var profilePicUrl = user.photoURL;
var userName = user.displayName;
// Set the user's profile pic and name.
this.userPic.style.backgroundImage = 'url(' + (profilePicUrl || '/images/profile_placeholder.png') + ')';
this.userName.textContent = userName;
// Show user's profile and sign-out button.
this.userName.removeAttribute('hidden');
this.userPic.removeAttribute('hidden');
this.signOutButton.removeAttribute('hidden');
// Hide sign-in button.
this.signInButton.setAttribute('hidden', 'true');
// We load currently existing chant messages.
this.loadMessages();
} else { // User is signed out!
// Hide user's profile and sign-out button.
this.userName.setAttribute('hidden', 'true');
this.userPic.setAttribute('hidden', 'true');
this.signOutButton.setAttribute('hidden', 'true');
// Show sign-in button.
this.signInButton.removeAttribute('hidden');
}
};
上述两个功能将确保UI根据用户是登录还是注销进行刷新(因此隐藏/显示“登录”按钮)
至于您的数据库消息,它们只有在登录正常时才会显示,因此希望修复上述问题将有助于显示您的消息
// Triggers when the auth state change for instance when the user signs-in or signs-out.
FriendlyChat.prototype.onAuthStateChanged = function(user) {
if (user) { // User is signed in!
// Get profile pic and user's name from the Firebase user object.
var profilePicUrl = user.photoURL;
var userName = user.displayName;
// Set the user's profile pic and name.
this.userPic.style.backgroundImage = 'url(' + (profilePicUrl || '/images/profile_placeholder.png') + ')';
this.userName.textContent = userName;
// Show user's profile and sign-out button.
this.userName.removeAttribute('hidden');
this.userPic.removeAttribute('hidden');
this.signOutButton.removeAttribute('hidden');
// Hide sign-in button.
this.signInButton.setAttribute('hidden', 'true');
// We load currently existing chant messages.
this.loadMessages();
} else { // User is signed out!
// Hide user's profile and sign-out button.
this.userName.setAttribute('hidden', 'true');
this.userPic.setAttribute('hidden', 'true');
this.signOutButton.setAttribute('hidden', 'true');
// Show sign-in button.
this.signInButton.removeAttribute('hidden');
}
};