Session 19
[Class Date]
{data}
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
{
"rules": {
".read": true,
".write": true
}
}
init() will create a connection between web app and firebase.
Establish the firebase connection in root.js by calling init() from firebase.js in constructor.
export const init = () => {
let config = {
apiKey: "XXXXXXXXXXXXXXXXXXXXXX",
authDomain: "realtime-todo-app.firebaseapp.com",
databaseURL: "https://realtime-todo-app.firebaseio.com",
storageBucket: "realtime-todo-app.appspot.com",
messagingSenderId: "XXXXXXXXXXXX"
}
firebase.initializeApp(config)
database = firebase.database()
}
src/components/root.js
import React, {Component} from 'react'
import {init as firebaseInit} from 'javascripts/firebase'
import {browserHistory} from 'react-router'
import Routes from './routes'
export default class Root extends Component {
constructor(props) {
super(props)
firebaseInit()
}
render() {
return (
<Routes history={browserHistory}/>
)
}
}
You app should be run with the same result. Nothing change in UI
Congratulation, we just linked the firebase and web app.
Finally, your src folder should look like this
src/
|- components
|- App/
|- root.js
|- routes.js
|- javascripts
|- firebase.js
{
id: 1,
name: "Daily",
todos: [{
id: 1,
name: "Feed the birds",
timestamp: 1288389400
},{
id: 2,
name: "Running",
timestamp: 1288989400
}],
timestamp: 1277385300
}
Data structure in this case means what are the data look like in our database. What are we going to store.