This is a newer version of old react firebase authentication boilerplate.
This newer version uses the not so new Context API from react to handle user data and firebase We're also using Typerscript!!
To execute this template with firebase features you need to have an web app registered inside Google Firebase.
- To start this app, first thing you need to clone it to your work place.
- Now you should run the command
npm install
oryarn
to install all the packages listed onpackage.json
. - You should get your firebase configuration keys in order to connect to your firebase console and we recommend to add them to an
.env
file with this structure:
REACT_APP_API_KEY=
REACT_APP_AUTH_DOMAIN=
REACT_APP_DATABASE_URL=
REACT_APP_PROJECT_ID=
REACT_APP_STORAGE_BUCKET=
REACT_APP_MESSAGING_SENDER_ID=
REACT_APP_APP_ID=
REACT_APP_MEASUREMENT_ID=
- After that, all you need to do is to run the project with
yarn start
This folder contains the pages of the project
- Home
- Login
- Regsiter
Where we define the contexts APIs responsible for handling login, register and logout functions. We also handle the authentication helpers like:
- getting the user from firebase
- seeing if the user is logged
- if it's authenticating (fetching firebase for the user)
We also defined an context for firebase, since we find that it helps to separate the logic between firebase configuration and the businness itself.
to access the contexts you can use
useFirebase
anduseAuthentication
we saw that on Kent C. Dodds blog and found it very clever. Thanks Kent ;)
Inside this file is where we pass the "global" providers of our App. Since authentication, firebase and routing(BrowserRouter) can be used in the entire application, we thought would be better to define them in a separated file.
- Firebase Authentication
- React Router to handle routing
- firebase
- react-router-dom
MIT © Samuel Monteiro