Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENGINEERING] Set up firebase-admin #6

Open
yxli001 opened this issue Feb 21, 2025 · 0 comments
Open

[ENGINEERING] Set up firebase-admin #6

yxli001 opened this issue Feb 21, 2025 · 0 comments
Assignees

Comments

@yxli001
Copy link
Collaborator

yxli001 commented Feb 21, 2025

What is the issue?

  • Set up the firebase-admin package
    • For the service-account-key.json file, I would download it from the firebase dashboard and copy the contents of the entire file into a field in .env instead of importing it from directly from the JSON file (make sure to add it to env validation)
    • Feel free to reference these two files (auth.ts and firebase.ts) from my TSE project if you need help
  • Create an auth middleware that checks for an authorization token in req.headers.authothorization in the format of Bearer [token] and decodes it into a user ID with firebase-admin's verifyIdToken auth function.
    • The decoded user ID should be put into req.userId so it can be used by the route handler
    • Use this middleware function, again, from my TSE project as reference. Note how it's being used in the user.ts route
  • Once the user model is created, make a GET /api/user/whoami route - which should be protected by the auth middleware - that uses the user ID that was put in req.userId by the auth middleware to query a user that has this userId from MongoDB and return it with res.json()

NOTE: pay attention to how errors are handled/thrown back to the request sender in the TSE sample files

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants