Review request

Habit tracker backend in FastAPI, please check the auth flow

Solved · 179 viewsasked by rosa_m

Repo or live app

git.example.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

2 answers

Marked as helpful by the asker
marco_py

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
olu_backend

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

Comment