Skip to content

fix: widen getTokenSilently overload return types to include undefined#1646

Open
yogeshchoudhary147 wants to merge 1 commit into
mainfrom
fix/get-token-silently-return-type
Open

fix: widen getTokenSilently overload return types to include undefined#1646
yogeshchoudhary147 wants to merge 1 commit into
mainfrom
fix/get-token-silently-return-type

Conversation

@yogeshchoudhary147

@yogeshchoudhary147 yogeshchoudhary147 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

The public overloads for getTokenSilently declare Promise<string> and Promise<GetTokenSilentlyVerboseResponse>, but the implementation can return undefined in two cases:

  • cacheMode: 'cache-only' with no matching cache entry — pre-existing behaviour; the overloads were already incorrect before IPSIE.
  • IPSIE session_expiry ceiling reached — introduced when the session expiry ceiling feature was added.

The implementation signature already reflects this (Promise<undefined | string | GetTokenSilentlyVerboseResponse>), but overload signatures are what callers see — the implementation signature is invisible externally.

This aligns the overloads with the implementation so consumers can write correct null checks without fighting the type system.

@yogeshchoudhary147 yogeshchoudhary147 requested a review from a team as a code owner July 1, 2026 08:44
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

getTokenSilently now declares undefined in both overloads, and the fetcher now accepts that possibility by typing token acquisition as optional and throwing a missing_access_token error when no token is returned.

Changes

Token return typing and fetcher validation

Layer / File(s) Summary
Update getTokenSilently return types
src/Auth0Client.ts
Both getTokenSilently overloads now return Promise<... | undefined>.
Handle missing access tokens in fetcher
src/fetcher.ts
AccessTokenFactory and Fetcher.getAccessToken now allow undefined, and prepareRequest throws GenericError('missing_access_token', ...) before setting authorization headers when no token is available.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: widening getTokenSilently overload return types to include undefined.
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.
✨ 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 fix/get-token-silently-return-type

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Auth0Client.ts (1)

321-331: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Widen AccessTokenFactory to include undefined. getTokenSilently({ detailedResponse: true }) returns Promise<GetTokenSilentlyVerboseResponse | undefined>, but src/fetcher.ts still requires Promise<string | GetTokenSilentlyVerboseResponse>. With strictNullChecks on, both getAccessToken callbacks in src/Auth0Client.ts:323-331 and src/Auth0Client.ts:2080-2085 will fail type-checking unless the factory type or the callback handles the undefined case.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Auth0Client.ts` around lines 321 - 331, The getAccessToken callbacks in
Auth0Client are returning a value from getTokenSilently(..., detailedResponse:
true) that can also be undefined, but AccessTokenFactory in fetcher.ts still
only allows string or GetTokenSilentlyVerboseResponse. Update the
AccessTokenFactory type to include undefined, or handle the undefined case
explicitly in the callbacks used by createFetcher and the other getAccessToken
site in Auth0Client so the strictNullChecks type error is resolved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/Auth0Client.ts`:
- Around line 321-331: The getAccessToken callbacks in Auth0Client are returning
a value from getTokenSilently(..., detailedResponse: true) that can also be
undefined, but AccessTokenFactory in fetcher.ts still only allows string or
GetTokenSilentlyVerboseResponse. Update the AccessTokenFactory type to include
undefined, or handle the undefined case explicitly in the callbacks used by
createFetcher and the other getAccessToken site in Auth0Client so the
strictNullChecks type error is resolved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cd1b544f-c340-492a-a32a-2b31636764f4

📥 Commits

Reviewing files that changed from the base of the PR and between 363fc68 and 405ea01.

📒 Files selected for processing (1)
  • src/Auth0Client.ts

@yogeshchoudhary147 yogeshchoudhary147 force-pushed the fix/get-token-silently-return-type branch from 405ea01 to cb64496 Compare July 1, 2026 09:02
@yogeshchoudhary147 yogeshchoudhary147 force-pushed the fix/get-token-silently-return-type branch from cb64496 to d556018 Compare July 1, 2026 09:06
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.

1 participant