Review request

Habit tracker backend in FastAPI, please check the auth flow

Solved · 7 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

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
olu_backend · edited

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

Comment