2016-10-15 14 views
1

После того, как я завершил часть «входа пользователя» в учебник, я убедился, что «http://localhost:5000» проверяет, что мой журнал функционировал правильно. Я сделал раздел «Чтение сообщений», и теперь я ничего не вижу. enter image description hereFirebase Вход не работает

Я также не вижу какой-либо из сообщений, которые я ввезенных ... 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; 
}; 

Это функции, которые мне пришлось изменить. Что я мог сделать, чтобы переопределить мою ранее правильную логическую реализацию, а также не получить доступ к сообщениям базы данных, которые я импортировал?

ответ

0

В любой момент вы можете проверить свой код в папке web, которая содержит готовый рабочий код для 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'); 
    } 
}; 

Эти две функции выше, убедитесь, что пользовательский интерфейс освежает в зависимости от кастрированный баран подписывается в Пользователем или подписан -out (и, следовательно, скрыть/показать кнопку «SIGN IN»).

Что касается сообщений в базе данных, они будут отображаться только в том случае, если вход в систему работает правильно, поэтому, надеюсь, исправление приведенного выше поможет отобразить ваши сообщения.

-1

Обсуждение на GitHub может быть полезным: https://github.com/firebase/friendlychat/issues/134

Если код управления скрытых атрибута в связанном входе <div>-х и <button> 'ы не в состоянии работать, код Логина будет скрыт по умолчанию ,

Смежные вопросы