После того, как я завершил часть «входа пользователя» в учебник, я убедился, что «http://localhost:5000» проверяет, что мой журнал функционировал правильно. Я сделал раздел «Чтение сообщений», и теперь я ничего не вижу. Firebase Вход не работает
Я также не вижу какой-либо из сообщений, которые я ввезенных ... FriendlyChat.prototype.initFirebase = функция() {// Ярлыки Firebase функций SDK. this.auth = firebase.auth(); this.database = firebase.database(); this.storage = firebase.storage(); // Инициирует Firebase auth и прослушивает изменения состояния пользователя. this.auth.onAuthStateChanged (this.onAuthStateChanged.bind (this)); // TODO (РАЗРАБОТЧИК): Инициализировать Firebase. };
// Loads chat messages history and listens for upcoming ones.
FriendlyChat.prototype.loadMessages = function() {
// TODO(DEVELOPER): Load and listens for new messages.
// Reference to the /messages/ database path.
this.messagesRef = this.database.ref('messages');
// Make sure we remove all previous listeners.
this.messagesRef.off();
// Loads the last 12 messages and listen for new ones.
var setMessage = function(data) {
var val = data.val();
this.displayMessage(data.key, val.name, val.text, val.photoUrl, val.imageUrl);
}.bind(this);
this.messagesRef.limitToLast(12).on('child_added', setMessage);
this.messagesRef.limitToLast(12).on('child_changed', setMessage);
};
};
// Saves a new message on the Firebase DB.
FriendlyChat.prototype.saveMessage = function(e) {
e.preventDefault();
// Check that the user entered a message and is signed in.
if (this.messageInput.value && this.checkSignedInWithMessage()) {
// TODO(DEVELOPER): push new message to Firebase.
}
};
...
FriendlyChat.prototype.signIn = function() {
// Sign in Firebase using popup auth and Google as the identity provider.
var provider = new firebase.auth.GoogleAuthProvider();
this.auth.signInWithPopup(provider);
// TODO(DEVELOPER): Sign in Firebase with credential from the Google user.
};
// Signs-out of Friendly Chat.
FriendlyChat.prototype.signOut = function() {
// TODO(DEVELOPER): Sign out of Firebase.
// Sign out of Firebase.
this.auth.signOut();
};
riendlyChat.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; // TODO(DEVELOPER): Get profile pic.
var userName = user.displayName; // TODO(DEVELOPER): Get user's name.
// Set the user's profile pic and name.
this.userPic.style.backgroundImage = 'url(' + profilePicUrl + ')';
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');
}
};
// Returns true if user is signed-in. Otherwise false and displays a message.
FriendlyChat.prototype.checkSignedInWithMessage = function() {
/* TODO(DEVELOPER): Check if user is signed-in Firebase. */
// Return true if the user is signed in Firebase
if (this.auth.currentUser) {
return true;
}
// Display a message to the user using a Toast.
var data = {
message: 'You must sign-in first',
timeout: 2000
};
this.signInSnackbar.MaterialSnackbar.showSnackbar(data);
return false;
};
Это функции, которые мне пришлось изменить. Что я мог сделать, чтобы переопределить мою ранее правильную логическую реализацию, а также не получить доступ к сообщениям базы данных, которые я импортировал?