rsnext/examples/with-firebase-authentication
abhik-b 583d1a0a02
Updated useUser.js (#14974)
UPDATE I ADDED:
setUser() 
AFTER REMOVING cookie IN return STATEMENT OF logout ARROW FUNCTION

There might be some cases where you do not want to redirect users after logout rather let them remain in that same page BUT let them know they have logged out by some UI changes .

For that cases you might need the 'user' hook to update when users logs out .

CURRENTLY the 'user' hook DOES NOT UPDATE AUTOMATICALLY when the user logs out . 
PAGE REFRESH NEEDED to update that.

So i propose that we might add setUser() to update user so that  user never returns true until user is set some value again
2020-07-13 23:43:21 +00:00
..
components [Examples] remove getInitialProps from with-firebase-authentication (#13895) 2020-06-11 17:38:29 +00:00
pages Update index.js (#14771) 2020-07-01 14:40:22 +00:00
utils/auth Updated useUser.js (#14974) 2020-07-13 23:43:21 +00:00
.env.local.example Added missing .env.local.example file for with example firebase-authentication-app (#14235) 2020-06-16 17:30:10 +00:00
package.json Remove next-cookies and prop-types (#14579) 2020-06-26 14:55:32 +02:00
README.md [Examples] remove getInitialProps from with-firebase-authentication (#13895) 2020-06-11 17:38:29 +00:00

Example: Firebase authentication with a serverless API

This example includes Firebase authentication and serverless API routes.

How to use

Using create-next-app

Execute create-next-app with Yarn or npx to bootstrap the example:

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 manually

Download the example:

curl https://codeload.github.com/vercel/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-firebase-authentication
cd with-firebase-authentication

Configuration

Set up Firebase:

  • Create a project at the Firebase console.
  • Copy the contents of .env.local.example into a new file called .env.local
  • Get your account credentials from the Firebase console at Project 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 project_id, client_email and client_id. Set them as environment variables in the .env.local file at the root of this project.
  • Get your authentication credentials from the Firebase console under Project settings > General> Your apps Add a new web app if you don't already have one. Under Firebase SDK snippet choose Config to get the configuration as JSON. It will include keys like apiKey, authDomain and databaseUrl. Set the appropriate environment variables in the .env.local file at the root of this project.
  • Go to Develop, click on Authentication and in the Sign-in method tab enable authentication for the app.

Install it and run:

npm install
npm run dev
# or
yarn
yarn dev

Deploy it to the cloud with Vercel (Documentation).

After deploying, copy the deployment URL and navigate to your Firebase project's Authentication tab. Scroll down in the page to "Authorized domains" and add that URL to the list.