Demo, all content is generated
Review request

Habit tracker backend in FastAPI, please check the auth flow

Solved · 178 views · asked by rosa_m · edited

Repo or live app

github.com/rosa-martin/habits-api

Unsure about: SecurityStructure

Cursor wrote JWT auth from scratch. Tokens work, but I don't know what I don't know.

Comment
Does the frontend use /users/{id} at all? If not, delete it rather than protect it. amir_h · edited

2 answers

Marked as helpful by the asker
marco_py · edited

Rolling your own JWT is where most of the risk is. Three findings: the secret is hardcoded in config.py (move to env), tokens never expire (exp missing), and /users/{id} returns any user given any valid token (compare id with the token's sub). Consider dropping the custom auth for Supabase Auth or Auth0 and keep FastAPI for the domain logic.

Comment
All three fixed. The /users one is scary in hindsight. rosa_m · edited
olu_backend · edited

Also add HTTPBearer(auto_error=True) as a router dependency so no endpoint can be added without auth by accident.

Comment