Review request

Habit-tracking API built with FastAPI, does the auth flow hold up?

Solved · 9 views · asked by kai_makes · edited

Repo or live app

github.com/kaitanaka/habit-api

Third app, first one with a real backend instead of just Supabase. ChatGPT walked me through JWT auth in FastAPI. It works end to end but I've never written auth myself before and I'd like someone who has to check I didn't skip a step.

Comment

1 answer

Marked as helpful by the asker
olu_backend · edited

Structurally fine, one real issue: verify_token catches JWTError but not ExpiredSignatureError separately, so an expired token currently returns a 500 instead of a 401. Split the except:

except ExpiredSignatureError:
    raise HTTPException(401, "token expired")
except JWTError:
    raise HTTPException(401, "invalid token")

Also your refresh tokens don't have a revocation check, fine for now at this scale, just know it's there if you ever need to log someone out remotely.

Comment