This project is used to provide an introduction to the Firebase services. The project will be used at the 2018-05-10 meetup for PEIDevs.
The recipe book is an old Kata I have been using for years as it requires little business logic but is extendable to various types of technologies. So it works for me as a quick prototype.
- Login
- Allows for login with a google account only. Future enhancements may allow other providers but for the demo, we will only use google auth
- Create New
- Creates a new Recipe. You do not have to be logged in to create a recipe.
- Favorite
- You have to be logged in to favorite a recipe. Shows the total number of users who have favorited a recipe. If you have favorited the recipe it shows up in red
- Node js 6+ LTS Recommended
- Google Account
- Clone the repo
- Install Dependencies
npm install - Start a new application in Firebase Console
- Setup Hosting
- Setup Database
- Setup rules, default of public should be ok to start, but be aware this isn't secure
- Setup Oauth, turning on for Google only
- Get the API keys and URL's from firebase
- Put the API keys and URL's in the
.envfile - Build the application
npm run build - install firebase tools
npm install -g firebase-tools - login to Firebase
firebase login - initialize the Firebase project
firebase init- When asked what to use as your public directory, respond with "build" (without quotes)
- Deploy the application
firebase deploy
- Clone Repo @ version without firebase files
- Run
npm install&&npm build - Files to have open
- App.js
- recipeRepository.js
- favoriterepository.js
- authRepository.js
- Introduction
- Stack
- React
- Firebase Hosting
- Firebase OAuth
- Firebase RT Database
- Additional Packages
- Material-UI + icons
- momentjs
- uuid
- Stack
- Show Current Demo and let people play
- Show DB + app at same time to show RT database
- Review Code - show Repos that utilize Firebase
- Review Console
- https://console.firebase.google.com
- Talking Points
- Basic Services - Expand on Stability, Analytics, Grow but dont go into them
- Project Overview - "Add Firebase to your web app"
- Auth - Logged In users, multiple providers
- Database - Data, Rules
- Hosting - Deployment History and rollback
- Demo
-
Create Application in console
- Leave the DB public
- setup new hosting name (peidevs-demo)
- Setup Auth for google only
-
Get api keys from firebase console
- update the values in
.env
- update the values in
-
install Firebase Tools
npm install -g firebase-tools
-
Init firebase w/ wizard
firebase loginorfirebase login --reauthfirebase init- You will be asked a series of questions. Answers in blue
- Are you ready to proceed? Yes
- Which Firebase CLI features do you want to setup for this folder? Press Space to select features, then Enter to confirm your choices. Hosting: Configure and deploy Firebase Hosting sites</style>
- Select a default Firebase project for this directory: pei-recipe (pei-recipe)</style>
- What do you want to use as your public directory? build</style>
- Configure as a single-page app (rewrite all urls to /index.html)? Yes
- File build/index.html already exists. Overwrite? No</style>
- You will be asked a series of questions. Answers in blue
-
Deploy the Code
npm run buildfirebase deploy
-
give new url and let people play again
-
- Secure DB - Showing Condole Simulator
- public
{
"rules": {
".read": true,
".write": true
}
}- secure to only logged in users
{
"rules": {
".read": true,
".write": "auth != null"
}
}- lock tables down and user can only edit their own data
{
"rules": {
"recipe" :{
".read": true,
".write": true
},
"favorite" :{
".read": true,
"$id" : {
"$userid" : {
".read": true,
".write": "$userid === auth.uid"
}
}
}
}
}- Data Validation
{
"rules": {
"recipe" :{
".read": true,
".write": true
},
"favorite" :{
".read": true,
"$id" : {
"$userid" : {
".read": true,
".write": "$userid === auth.uid",
".validate" : "newData.isBoolean() && data.val() != newData.val()"
}
}
}
}
}- Can we use API keys to deliver from CI
- https://medium.com/@rohanbagchi/how-to-setup-continuous-integration-for-your-firebase-app-cd183bb862e1
- Console -> Cog -> Users and Permissions
- Cost?
- Free, $25, Pay/usage
- What other Features are available?
- Functions, Messaging, Storage, new DB, analytics
- Hosting Rollback
- Console shows recent deploy history. Click of button reverts back to old version