mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-15 03:01:09 +02:00
fix(mana-auth): avoid error.body access in login catch — triggers async stream read
Accessing (error as any)?.body?.code on a Better Auth APIError triggers an internal async stream read. When the request body contains special chars like '!', the deferred JSON parse fails as an unhandled rejection that races with the response, causing 500. Use only error.status === 'FORBIDDEN' which is a simple string property. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e624756d66
commit
c6448a63bc
1 changed files with 4 additions and 4 deletions
|
|
@ -142,10 +142,10 @@ export function createAuthRoutes(
|
|||
|
||||
return c.json(response);
|
||||
} catch (error) {
|
||||
// Better Auth throws APIError (status="FORBIDDEN", body.code="EMAIL_NOT_VERIFIED")
|
||||
const isEmailNotVerified =
|
||||
(error as any)?.body?.code === 'EMAIL_NOT_VERIFIED' ||
|
||||
(error as any)?.status === 'FORBIDDEN';
|
||||
// Better Auth throws APIError with status="FORBIDDEN" for unverified emails.
|
||||
// Do NOT access error.body — it may be an async stream that triggers unhandled
|
||||
// promise rejections when the request body contains special characters (e.g. !).
|
||||
const isEmailNotVerified = (error as any)?.status === 'FORBIDDEN';
|
||||
if (isEmailNotVerified) {
|
||||
return c.json({ error: 'Email not verified', code: 'EMAIL_NOT_VERIFIED' }, 403);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue