Skip to content

Conversation

@faizi-7
Copy link

@faizi-7 faizi-7 commented Dec 18, 2025

Fix: Prioritize URL access tokens over storage when using magic links
Summary
This PR fixes an issue where getAccessToken prioritizes localStorage tokens over URL hash tokens, causing magic links to fail when users already have a stored token.

Problem: When implementing passwordless authentication via magic links, the getAccessToken method checks localStorage before examining the URL hash. This means users with a stale token in storage cannot authenticate via a fresh magic link - the old token is used instead of the new one from the URL.

Solution: Modified getAccessToken to:

Check the URL hash for an access token before checking storage
Return the URL token even if a different token exists in storage
Clear (remove) the stored token when a URL token is consumed
Related Issues
Fixes #3631
Other Information
This change aligns with the expected behavior described in the original issue - if a user provides a new token in the URL, Feathers should consume it instead of using the previous one from localStorage.

Use case: Magic links to applications where a user can open a specific page without requiring login first because the token is part of the URL. Previously, opening two different magic links in the same browser would fail because the first token was cached.

Changes:

packages/authentication-client/src/core.ts

  • Modified getAccessToken to prioritize URL tokens
    Added test case to verify URL token priority behavior

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

1 participant