Basic project to test firebase authentication with angular frontend and fastapi backend.
Medium article:
-
python 3.10 or above, for ex with pyenv: https://github.com/pyenv/pyenv
-
node v20.9.0 or above, for ex with nvm: https://github.com/nvm-sh/nvm
-
angular cli: v17 or above: see https://angular.io/cli
-
firebase admin for backend:
- Go to your firebase console
- Click on
Project Settingsthen service accounts - Then click
Generate new private key - Save it as
service-account.jsonin thebackendfolder. Do not commit it!!
- Run
make installto create environments and install dependencies - Don't forget to activate python environment afterwards:
source venv/bin/activate
Note: look at the Makefile to see the details of the installation
- Installation should have created a
.envfile in thebackendfolder. - Note that there is no sensitive information in this application so you won't need to modify it
-
The simplest way is to use vscode task:
Run appwhich will run the backend and the frontend You can check the details of the commands in.vscode/tasks.json -
Alternatively,
- in
backendfolder, runuvicorn app.main:app --reload - in
frontendfolder:ng serve
- in
-
Check that frontend is running by going to
http://localhost:4200 -
Check that backend is running by going to
http://localhost:8000/docs
- In the frontend, you can click on the links to go to a different route.
- First, click on
Signin pageand log in with your google account - Then click on
Auth protected, you should be able to access it (it will not work if you are not logged in) - Then go back to
Landing pageand clickGet user id. If you open the console, you should see your user id, which matches what is saved in firebase. You can also check the network tab to see that the request to the backend contains the authorization header with the bearer token.