Coder Social home page Coder Social logo

mejustdev / firebase-mongodb-auth-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 29.44 MB

Firebase-MongoDb Auth w/ Next.js Custom Server

Home Page: https://firemon.herokuapp.com/

JavaScript 100.00%
firebase firebase-auth mongodb express-js nextjs react

firebase-mongodb-auth-boilerplate's Introduction


Nextjs Firebase Mongodb w/ Custom Server deployed on Heroku

Table of contents

Why Custom Server and Firebase w/ MongoDb

  1. You can have a look example of custom server express on Vercel repo, another example with Passport.js and Next-Express.js npm package.
  2. According to Next.js documentation
  • A custom server can not be deployed on Vercel. Next.js can be deployed to any hosting provider that supports Node.js.
  • server.js doesn't go through babel or webpack.
  • A custom server will remove important performance optimizations, like serverless functions and Automatic Static Optimization( means If getServerSideProps or getInitialProps is present in a page, Next.js will switch to render the page on-demand, per-request (meaning Server-Side Rendering). If the above is not the case, Next.js will statically optimize your page automatically by prerendering the page to static HTML.)
  1. Please have a look this discussion if you want to learn what are the some gotchas like:
  • With custom server you can't remap urls that are automatic static optimization.
  1. After building, next start starts a Node.js server that supports hybrid pages, serving both statically generated and server-side rendered pages.

This project is improved based on this course. It is a small boilerplate auth app combination of Firebase, Mongodb, Express.js and Nextjs.

Quick Start

Add project credentials & secrets

  • .env ---> client/.env
  • .next.config.js ---> client/next.config,js
  • serviceAccountKey.json ---> firebase/serviceAccountKey.json

.env

DATABASE= '<mongodb_uri>'
PORT= 8000

.next.config.js

module.exports = {
  env: {
    api: '<your_domain>/api',
    passwordResetRedirect: '<your_domain>/login',
    NEXT_PUBLIC_FB_API_KEY: ''
    NEXT_PUBLIC_FB_AUTH_DOMAIN: ''
    FB_PROJECT_ID: ''
    FB_STORAGE_BUCKET:''
    FB_MESSAGING_SENDER_ID: ''
    FB_APP_ID:''
    DATABASE: '<mongodb_uri>' 
    PORT: 8000,
  },
};

๐Ÿ’ฅ Before pushing remote create .gitignore file inside client folder and add โ˜๏ธ those files in there.

  • Make sure you have installed Node.js and npm.
  • NOTE: In the rest of the documentation, you will come across npm being used for running commands. To use yarn in place of npm for the commands, simply substitute npm for yarn. Example, npm start as yarn start. For more help, checkout migrating from npm.

Install Dependencies

cd client

npm install

Run both Express & React from root

npm run dev

Build for production

cd client

npm run build

Check in browser on http://localhost:8000/

Deploy to Heroku

This may not be ideal approach but works

git checkout -b production

git add -f .env next.config.js serviceAccountKey.json

DON'T PUSH THE PRODUCTION BRANCH TO GITHUB

Git Flow

git commit -m 'ready to deploy'

heroku create

git push heroku production:main

Once you succesfully deploy your app,

  • Go to Firebase console add your domain. Authentication / Sign-in Method / Authorized domain
  • Update <your_domain> in next.config.js with the given domain and follow โ˜๏ธ Git Flow again

If you want to rename your app follow this link

Feature Plan

  • Tailwind css
  • More helper/util functions
  • Custom hooks

Contributing

"If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome."

Links

Licensing

"The code in this project is licensed under MIT license."

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.