Code Monkey home page Code Monkey logo

next-blog-firestore's Introduction

Next Blog Firestore

code style: prettier style: styled-components

Next Blog Firestore

This blog uses Next.js for SSR & Firebase Firestore API for storing and fetching data. Create and edit your content in simple custom content management system built with React, Mobx State Tree and Styled Components.

Clone this repo and use it as starting point to create your own fancy blog.

Technology stack:

What you get:

  • Posts feed
  • Featured posts
  • Posts by tags and category
  • Multi language support
  • Multi author support
  • Markdown with ability to use custom React components
  • Simple and convenient CMS inspired by Ghost
  • CMS is protected by Firebase Auth
  • Quick and SEO-friendly responses with SSR
  • Good results in Lighthouse

Getting started

Step 1. Create Firebase account

Create Firebase account

Step 2. Setup Authentication Method

  • Click Set up sign-in method on Authentication section.
  • Enable just Google authentication provider.
  • Add your domain (if you have one) to Authorized domains.

Setup authentication

Step 3. Create Firestore database

  • Go to Database section and create Firestore instance.

Create Firestore database

Firestore is still in beta, but it doesn't make it less awesome.

Step 4. Database configuration.

  • Go to Rules section in your database and paste configuration from .firebase-rules in project root.
  • Publish new rules.

Step 5. Set up Firebase secret keys for our app.

  • Create .env at the root of the project. Do not commit this file. It is personal data that should not be available for everyone.
  • Go to Project settings in Firebase console (click on the gear icon next to Project Overview).
  • Copy data from this page to .env in the following format:
F_PROJECT_ID=<your Project ID>
F_AUTH_DOMAIN=<your Project ID>.firebaseapp.com
F_API_KEY=<your Web API Key>

Step 6. Set up Firebase Admin SDK key for importing/exporting data from database.

In order to be able to initialize database with initial seed we need to generate private Firebase Admin service key.

  • Go to Project Settings > Service Accounts and click Generate new private key button.
  • Save downloaded file as firebase-service-key.json at project root. ** Do not commit this file. It's added to .gitignore by default.

Step 7. Initialize database with initial data.

We almost finished. Let's initialize our database with initial data.

yarn
yarn run seed

Step 8. Setup database indexes.

We need manually setup indexes in our Firestore database to be able to make REST requests to our Firebase.

  • Go to Database > Indexes and create the following index.

Create indexes

Step 9. Run blog locally.

We're ready to launch our blog locally.

yarn dev

Blog is up and running on http://localhost:3000.

Step 10. Sign in to admin part.

Wait.. But what's about CMS part?

  • Go to http://localhost:3000/admin and click on "Click to start writing".
  • Sign-in with your Google Account in popup window.
  • Go to Firebase Console and add author rights to account you just signed in with.
    • Copy User UID in Authentication section.
    • Create authors collection in Database
    • Create a record in authors collection, where documentId is UID of the user and name is id of user in config.js file.

Map author and user

Step 11. Ready to go!

License

Licensed under the MIT License, Copyright © 2018-present Alexander Suevalov

See LICENSE for more information.

next-blog-firestore's People

Contributors

suevalov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.