Skip to content

fix(authentication-client): prioritize window.location token over stored token in getAccessToken - #3733

Open
EnesKartal wants to merge 1 commit into
feathersjs:dovefrom
EnesKartal:fix/auth-client-url-token
Open

EnesKartal wants to merge 1 commit into
feathersjs:dovefrom
EnesKartal:fix/auth-client-url-token

Conversation

@EnesKartal

Copy link
Copy Markdown

Fixes #3631

Summary

Previously, AuthenticationClient.getAccessToken() checked this.storage.getItem(this.options.storageKey) first and only called this.getFromLocation(window.location) if no token was found in storage. When a user already had an access token in storage and navigated to a URL containing a new token (such as a magic link or OAuth callback), the new token in window.location was ignored and the old stored token continued to be used.

Changes

  • packages/authentication-client/src/core.ts:
    • Updated getAccessToken() to check this.getFromLocation(window.location) first when window.location is available.
    • When a token is found in window.location, removes any existing stored token via this.removeAccessToken() and returns the new token.
    • Falls back to this.storage.getItem(this.options.storageKey) when no token is present in window.location.
  • packages/authentication-client/test/index.test.ts:
    • Added a regression test verifying that getAccessToken() prefers a token in window.location over an existing stored token, clears the hash, and removes the stale token from storage.

Verification

  • npx lerna run compile --scope=@feathersjs/authentication-client --include-dependencies (succeeded for 16 projects)
  • npm test --workspace=@feathersjs/authentication-client (27 passing)
  • npx prettier --check packages/authentication-client/src/core.ts packages/authentication-client/test/index.test.ts (passed)
  • npx eslint packages/authentication-client/src/core.ts packages/authentication-client/test/index.test.ts (passed)

@daffl

daffl commented Nov 20, 2026

Copy link
Copy Markdown
Member

Thank you. This has been discussed before in #3633 (and other issues which I still can't seem to find).

This branch has not been deployed

No deployments
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.

Authenticate twice using an access token in the URL might not work as expected

2 participants