Handle malformed login request bodies#191
Conversation
Greptile SummaryThis PR fixes a crash/unexpected error path in the login route by replacing the bare
Confidence Score: 5/5Safe to merge — the change is a narrow, well-tested guard that stops invalid request bodies before they reach Supabase. The only modification to the login route is swapping one line (request.json()) for an already-proven helper (safeParseBody) that exists elsewhere in the codebase, plus a null guard. The regression test directly covers the failure scenario, and the rest of the auth flow is unchanged. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant LoginRoute as POST /api/auth/login
participant RateLimit as Rate Limiter
participant SafeParse as safeParseBody
participant Schema as loginSchema
participant Supabase
Client->>LoginRoute: POST (body)
LoginRoute->>RateLimit: checkRateLimit(identifier)
alt Rate limit exceeded
RateLimit-->>LoginRoute: allowed: false
LoginRoute-->>Client: 429 Rate Limited
else Rate limit OK
RateLimit-->>LoginRoute: allowed: true
LoginRoute->>SafeParse: safeParseBody(request)
alt Malformed / empty / non-object JSON
SafeParse-->>LoginRoute: null
LoginRoute-->>Client: 400 Invalid request body
else Valid JSON object
SafeParse-->>LoginRoute: parsed body
LoginRoute->>Schema: safeParse(body)
alt Schema invalid
Schema-->>LoginRoute: error
LoginRoute-->>Client: 400 validation error
else Schema valid
Schema-->>LoginRoute: "{ email, password }"
LoginRoute->>Supabase: signInWithPassword(email, password)
alt Auth error
Supabase-->>LoginRoute: error
LoginRoute-->>Client: 401 Unauthorized
else Unconfirmed email
Supabase-->>LoginRoute: user (no email_confirmed_at)
LoginRoute->>Supabase: signOut()
LoginRoute-->>Client: 403 EMAIL_NOT_CONFIRMED
else Success
Supabase-->>LoginRoute: user + session
LoginRoute-->>Client: 200 Login successful
end
end
end
end
Reviews (2): Last reviewed commit: "Handle malformed login bodies" | Re-trigger Greptile |
Summary
Fixes #190
uGig task
Submitted for the active uGig repo testing task: https://ugig.net/gigs/4741218f-a723-46bb-82cb-6516120331ae
No payout details included; those can be provided after acceptance.
Tests