Skip to content

fix(oauth): read the OAuth error code from a nested details object - #121

Merged
Bccorb merged 2 commits into
mainfrom
fix/oauth-error-code-nested-details
Jul 30, 2026
Merged

fix(oauth): read the OAuth error code from a nested details object#121
Bccorb merged 2 commits into
mainfrom
fix/oauth-error-code-nested-details

Conversation

@Bccorb

@Bccorb Bccorb commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Closes #120

getOAuthErrorCode read the OAuth failure code from a top-level code key on the parsed error body, which is where the auth API puts it ({ error, message?, code? }, see src/schemas/oauth.responses.ts in seamless-auth-api). That hard-coupled the SDK to the API's exact top-level shape: any intermediary that normalized the error body broke OAuth messaging silently, because code read as undefined and the UI fell back to a generic error instead of the user-actionable message.

That already happened in practice. fells-code/seamless-auth-server#124 had to forward auth API error bodies verbatim specifically because normalizing them (moving the siblings of error under a details object) broke this function, and that constraint now blocks cleanup work in that repo.

Change

getOAuthErrorCode now accepts the code in either location: the top level first, exactly as before, then a nested details object when the top level does not carry one. Everything else is unchanged, including the public signature and the allowlist, so an unrecognized code in either place still returns undefined and callers keep their generic messaging.

Tests

Added coverage in tests/errors.test.ts for each known code nested under details, top level winning when both are present, an unrecognized code in each location, details present without a code, a null/undefined/non-object body, and a non-object details.

Checks

npm test -- --runInBand (31 suites, 276 tests passing), npm run typecheck, npm run lint, npm run format:check, and npm run build all pass locally.

Patch changeset included since this changes user-facing behavior for adopters behind a normalizing proxy.

Bccorb and others added 2 commits July 29, 2026 19:59
getOAuthErrorCode only looked at a top-level `code`, which is where the
auth API puts it. That made the SDK depend on the API's exact top-level
error shape: any proxy that normalized the body and moved the siblings of
`error` under `details` silently dropped the code, so the UI fell back to
generic messaging instead of the user-actionable message.

seamless-auth-server#124 hit this and had to forward auth API error
bodies verbatim to work around it, which now constrains error handling
there. Accept both locations, top level first, and keep the allowlist
unchanged so an unrecognized code in either place still returns
undefined.

Closes #120
@Bccorb
Bccorb merged commit a82768d into main Jul 30, 2026
3 checks passed
@Bccorb
Bccorb deleted the fix/oauth-error-code-nested-details branch July 30, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getOAuthErrorCode only reads a top-level code, so a normalized error body silently loses OAuth messaging

1 participant