Skip to content

Conversation

Brunonascdev
Copy link
Contributor

@Brunonascdev Brunonascdev commented Oct 19, 2025

To be merged after #21390

Description

This PR moves the Card authentication verification logic out of the CardSDK context.
With this change, the app can determine whether a user is authenticated with Card even before they open the Card screen.

This enables us to:

  • Dynamically show or hide the Card button based on authentication state.
  • Automatically log out users when their refresh token expires.

Changelog

CHANGELOG entry: Refactored Card authentication to enable pre-screen checks

Related issues

Fixes:

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Moves Card auth verification out of the SDK context into app-level hooks/thunks, adds token refresh/storage utilities, updates SDK and Redux state/selectors for auth and user location.

  • Card Auth Verification (App-level):
    • New useCardAuthenticationVerification hook dispatches verifyCardAuthentication on login/flag changes.
    • CardVerification now invokes both useCardholderCheck and useCardAuthenticationVerification.
  • Redux (card slice):
    • Added verifyCardAuthentication thunk; new state isAuthenticated flow and userCardLocation with selectors/actions (selectIsAuthenticatedCard, selectUserCardLocation, setUserCardLocation).
    • Extended selectors to support authenticated cache; kept display button logic considering authentication.
  • Token Storage/Refresh:
    • New utils: handleLocalAuthentication, refreshCardToken.
    • cardTokenVault now stores accessTokenExpiresAt/refreshTokenExpiresAt (ms conversion), validates data, and returns null when absent.
  • SDK Changes (CardSDK):
    • Accepts userCardLocation; auto-sets x-us-env header internally; removed per-call location params and refreshLocalToken.
    • Auth endpoints updated accordingly; tests adjusted.
  • Provider/Auth Hook:
    • CardSDKProvider simplified to SDK init only; logout clears auth state.
    • useCardProviderAuthentication stores new token fields and dispatches setUserCardLocation.
  • Priority Token Hook:
    • Cache validity requires both recent lastFetched and a token; effect early-returns consolidated.
  • UI:
    • Login button now disabled while loading.
  • Tests:
    • Comprehensive updates/additions across hooks, SDK, token utils, and Redux to cover new flows.

Written by Cursor Bugbot for commit 175a2a4. This will update automatically on new commits. Configure here.

Brunonascdev and others added 30 commits October 2, 2025 23:06
…taMask/metamask-mobile into chore/card-api-integration-foundation
@Brunonascdev Brunonascdev self-assigned this Oct 19, 2025
@Brunonascdev Brunonascdev added the team-card Card Team label Oct 19, 2025
@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@Brunonascdev Brunonascdev marked this pull request as ready for review October 20, 2025 16:35
@Brunonascdev Brunonascdev requested a review from a team as a code owner October 20, 2025 16:35
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 97.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.21%. Comparing base (d68cc52) to head (b9104a4).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
app/components/UI/Card/util/refreshCardToken.ts 91.89% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21399      +/-   ##
==========================================
+ Coverage   77.11%   77.21%   +0.10%     
==========================================
  Files        3615     3641      +26     
  Lines       89144    89498     +354     
  Branches    16861    16947      +86     
==========================================
+ Hits        68745    69108     +363     
+ Misses      15721    15709      -12     
- Partials     4678     4681       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud
Copy link

@Brunonascdev Brunonascdev added this pull request to the merge queue Oct 21, 2025
Merged via the queue into main with commit 20a5b00 Oct 21, 2025
82 of 83 checks passed
@Brunonascdev Brunonascdev deleted the feat/card-authentication-global-context branch October 21, 2025 01:37
@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2025
@metamaskbot metamaskbot added release-7.59.0 Issue or pull request that will be included in release 7.59.0 release-7.58.0 Issue or pull request that will be included in release 7.58.0 and removed release-7.59.0 Issue or pull request that will be included in release 7.59.0 labels Oct 21, 2025
@metamaskbot
Copy link
Collaborator

Missing release label release-7.58.0 on PR. Adding release label release-7.58.0 on PR and removing other release labels(release-7.59.0), as PR was added to branch 7.58.0 when release was cut.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.58.0 Issue or pull request that will be included in release 7.58.0 size-XL team-card Card Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants