With Firebase Authentication example
How to use
npx create-next-app --example with-firebase-authentication with-firebase-authentication-app # or yarn create next-app --example with-firebase-authentication with-firebase-authentication-app
Download the example:
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-firebase-authentication cd with-firebase-authentication
Set up firebase:
- Create a project at the Firebase console.
- Get your account credentials from the Firebase console at settings>service accounts, where you can click on generate new private key and download the credentials as a json file. It will contain keys such as
client id. Now copy them into your project in the
- Get your authentication credentials from the Firebase console under authentication>users>web setup. It will include keys like
databaseUrland it goes into your project in
- Copy the
databaseUrlkey you got in the last step into
server.jsin the corresponding line.
- Back at the Firebase web console, go to authentication>signup method and select Google.
Install it and run:
npm install npm run dev # or yarn yarn dev
The idea behind the example
The goal is to authenticate users with firebase and store their auth token in sessions. A logged in user will see their messages on page load and then be able to post new messages.