Skip to content

fix(browser/react/vue): pass url.search to hasAuthParamsInUrl instead of falling back to window.location.search - #1

Open
Sdnsoumy wants to merge 1 commit into
Infosys:mainfrom
Sdnsoumy:fix/has-auth-params-use-url-search
Open

fix(browser/react/vue): pass url.search to hasAuthParamsInUrl instead of falling back to window.location.search#1
Sdnsoumy wants to merge 1 commit into
Infosys:mainfrom
Sdnsoumy:fix/has-auth-params-use-url-search

Conversation

@Sdnsoumy

@Sdnsoumy Sdnsoumy commented Aug 1, 2026

Copy link
Copy Markdown

Purpose

hasAuthParams(url, afterSignInUrl) accepts a URL argument but both the React hook (useBrowserUrl) and the Vue provider (ThunderIDProvider) called hasAuthParamsInUrl() with no argument, silently ignoring url.search and always falling back to window.location.search.

This makes the helpers untestable in isolation (you cannot pass an arbitrary URL) and would produce incorrect results in any scenario where the caller's url differs from the current window location (e.g. during navigation events, SSR hydration, or unit tests).

Also fixes a JSDoc mismatch on hasAuthParamsInUrl: the description claimed it checks for both code and session_state, but the implementation only checks for code.

Approach

  • Pass url.search explicitly to hasAuthParamsInUrl(url.search) in both call sites (useBrowserUrl.ts and ThunderIDProvider.ts).
  • Correct the JSDoc in hasAuthParamsInUrl.ts to match the actual behaviour.

No behaviour change in production (both callers already pass the current window URL), but the helpers are now correct by construction and fully testable.

Related Issues

  • N/A

… of falling back to window.location.search

hasAuthParams(url, afterSignInUrl) accepted a URL argument but called
hasAuthParamsInUrl() with no argument, silently ignoring url.search and
always checking window.location.search instead. This makes the helpers
untestable in isolation and incorrect whenever the provided URL differs
from the current window location.

Fix all call sites to pass url.search explicitly. Also correct the JSDoc
on hasAuthParamsInUrl: the function only checks for 'code', not both
'code' and 'session_state' as the old description claimed.
Copilot AI review requested due to automatic review settings August 1, 2026 11:40

Copilot AI 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.

Pull request overview

Fixes browser auth-param detection to use the caller-provided URL consistently (instead of implicitly reading window.location.search), improving correctness in non-window scenarios (tests, navigation, SSR hydration) and aligning documentation with actual behavior.

Changes:

  • Pass url.search explicitly to hasAuthParamsInUrl(url.search) from the React hook and Vue provider call sites.
  • Update hasAuthParamsInUrl JSDoc to reflect that it checks for code (not code + session_state).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/vue/src/providers/ThunderIDProvider.ts Passes url.search to hasAuthParamsInUrl to ensure correct URL evaluation.
packages/react/src/hooks/useBrowserUrl.ts Passes url.search to hasAuthParamsInUrl to avoid falling back to window.location.search.
packages/browser/src/utils/hasAuthParamsInUrl.ts Updates JSDoc to match the function’s actual detection logic (code).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 60 to 62
const hasAuthParams = (url: URL, afterSignInUrl: string): boolean =>
(hasAuthParamsInUrl() && new URL(url.origin + url.pathname).toString() === new URL(afterSignInUrl).toString()) ||
(hasAuthParamsInUrl(url.search) && new URL(url.origin + url.pathname).toString() === new URL(afterSignInUrl).toString()) ||
// authParams?.authorizationCode || // FIXME: These are sent externally. Need to see what we can do about this.
* Utility to check if `code` and `session_state` are available in the URL as search params.
* Utility to check if `code` is available in the URL as a search param.
*
* @param params - The URL search params to check. Defaults to `window.location.search`.
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