You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
What is the issue?
firebase-admin
packageservice-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)auth.ts
andfirebase.ts
) from my TSE project if you need helpreq.headers.authothorization
in the format ofBearer [token]
and decodes it into a user ID with firebase-admin'sverifyIdToken
auth function.req.userId
so it can be used by the route handleruser.ts
routeGET /api/user/whoami
route - which should be protected by the auth middleware - that uses the user ID that was put inreq.userId
by the auth middleware to query a user that has this userId from MongoDB and return it withres.json()
NOTE: pay attention to how errors are handled/thrown back to the request sender in the TSE sample files
Additional context
The text was updated successfully, but these errors were encountered: