Skip to content

feat(auth0-server-js): export TokenExchangeError from public surface#195

Merged
cschetan77 merged 2 commits into
mainfrom
feat/export-token-exchange-error
Jun 17, 2026
Merged

feat(auth0-server-js): export TokenExchangeError from public surface#195
cschetan77 merged 2 commits into
mainfrom
feat/export-token-exchange-error

Conversation

@cschetan77

@cschetan77 cschetan77 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Re-exports TokenExchangeError and MissingClientAuthError from @auth0/auth0-auth-js in the auth0-server-js public surface
  • Both loginWithCustomTokenExchange() and customTokenExchange() are documented as throwing these errors, but consumers had no way to import them from @auth0/auth0-server-js — they were forced to reach into @auth0/auth0-auth-js directly (a transitive dependency) or fall back to matching on error.name
  • TokenExchangeError: thrown when the exchange fails (bad subject token, Auth0 rejects the request, validation errors)
  • MissingClientAuthError: thrown when the client is not configured with a clientSecret or clientAssertionSigningKey — CTE requires a confidential client
  • Framework SDKs built on top of auth0-server-js (e.g. auth0-fastify) can now re-export both errors cleanly without adding auth0-auth-js as a direct dependency
  • Follows the same pattern as TokenResponse and ActClaim added in feat(auth0-server-js): export TokenResponse and ActClaim types #194

Consumers of loginWithCustomTokenExchange() and customTokenExchange()
need to catch TokenExchangeError by value (instanceof), but the class
lived only in auth0-auth-js which is a transitive dependency. Re-export
it so framework SDKs like auth0-fastify can surface it without taking a
direct dependency on auth0-auth-js.
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A single line is added to packages/auth0-server-js/src/index.ts to re-export TokenExchangeError from @auth0/auth0-auth-js, making the error type directly importable from the auth0-server-js package.

Changes

TokenExchangeError Public Export

Layer / File(s) Summary
Re-export TokenExchangeError in package index
packages/auth0-server-js/src/index.ts
Adds TokenExchangeError re-export from @auth0/auth0-auth-js to the public surface of auth0-server-js.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • auth0/auth0-auth-js#176: Introduces Custom Token Exchange methods and tests that rely on TokenExchangeError being surfaced on exchange failures — directly motivating this re-export.

Suggested reviewers

  • nandan-bhat

Poem

A tiny line, a single re-export so neat,
🐇 The rabbit hops and says, "Now errors are complete!"
TokenExchangeError leaps into the light,
No hidden imports needed — all in plain sight.
One line of code, yet perfectly right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly describes the main change: exporting TokenExchangeError from the public API surface of auth0-server-js.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/export-token-exchange-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

… surface

Both customTokenExchange() and loginWithCustomTokenExchange() throw
MissingClientAuthError when the client is not configured with credentials.
Same gap as TokenExchangeError — export it so consumers can catch it by
value without reaching into auth0-auth-js directly.
@cschetan77 cschetan77 merged commit dfd3780 into main Jun 17, 2026
16 checks passed
@cschetan77 cschetan77 deleted the feat/export-token-exchange-error branch June 17, 2026 05:01
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.

2 participants