Commit d2366be5 authored by Alexander Kotov's avatar Alexander Kotov

send message to firebase

parent fd1e5477
......@@ -8,6 +8,8 @@ import authWithGoogle from './authWithGoogle';
import firebase from './firebase'
const database = firebase.database()
const messagesRef = database.ref('messages')
const timestamp = firebase.database.ServerValue.TIMESTAMP;
class App extends Component {
state = {
......@@ -19,12 +21,12 @@ class App extends Component {
let user = authUser && {
photoURL: authUser.photoURL,
displayName: authUser.displayName,
email: authUser.email
email: authUser.email,
uid: authUser.uid
}
this.setState({ user });
})
let messagesRef = database.ref('messages')
messagesRef.on('child_added', data => {
let message = data.val()
this.addMessage(message)
......@@ -32,7 +34,11 @@ class App extends Component {
}
sendMessage = (message) => {
messagesRef.push({
...message,
uid: this.state.user.uid,
timestamp
}, console.error);
}
addMessage(message) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment