## **Description**
Part 1 of 5 replacing MetaMask#44367.
Local development sometimes needs DEV Profile Sync (for example staging
ramps). Identity JWTs are shared by many `getBearerToken` consumers, so
flipping every `yarn start` to DEV by default would mint DEV tokens
against services that still talk to PRD.
This follows the Mobile pattern:
1. Opt in with `MM_DEV_API_ENV=dev` in `.metamaskrc` (default remains
prod). Restart `yarn start` after changing it.
2. A single source (`devApiEnv` / `loadAuthenticationConfig`) is used by
AuthenticationController, User Storage, Profile Metrics, Config
Registry, and Authenticated User Storage so those backends agree.
3. Settings → Debug → Backup and sync shows the current identity env and
can clear the persisted auth session via `performSignOut` after you flip
the flag.
`FORCE_AUTH_MATCH_BUILD` is unchanged for beta/UAT. Notifications,
shield, money-account, bridge, and perps stay on PRD in this PR.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Replaces part of MetaMask#44367.
## **Manual testing steps**
1. Leave `MM_DEV_API_ENV` unset and confirm Profile Sync still uses
production (`oidc.api.cx.metamask.io`).
2. Set `MM_DEV_API_ENV=dev` in `.metamaskrc` and restart `yarn start`.
3. Open Settings → Debug → Backup and sync, confirm the identity env
shows `dev`, and click Clear auth session.
4. Unlock / sign in to Backup & Sync and confirm Network requests go to
`oidc.dev-api.cx.metamask.io`.
5. Unset the flag, restart, clear the session again, and confirm
production identity is restored.
<!--
## **Screenshots/Recordings**
### **Before**
### **After**
-->
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
---
Stack: MetaMask#46042 → MetaMask#46043 → MetaMask#46044 → MetaMask#46045 → MetaMask#46046
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes authentication environment selection and JWT/backend alignment
for Backup & Sync and related identity services; misconfiguration could
break sign-in until the session is cleared.
>
> **Overview**
> Adds an **opt-in local dev switch** (`MM_DEV_API_ENV=dev` in
`.metamaskrc`) so Profile Sync identity stays on **prod by default**
during `yarn start`, avoiding DEV JWTs against services that still use
PRD.
>
> **`devApiEnv()`** and updated **`loadAuthenticationConfig()`**
centralize env selection: DEV only when development build + explicit
flag; **`FORCE_AUTH_MATCH_BUILD`** still maps beta/uat to UAT; non-local
builds ignore the flag. **Authenticated User Storage** init now maps
**`Env.DEV`** → `dev` so it stays aligned with auth JWT env.
>
> **Settings → Debug → Backup and sync** shows the active identity env
and adds **Clear auth session** (`performSignOut`) for after flipping
the flag. Docs/build defaults (`builds.yml`, `.metamaskrc.dist`) and
unit tests cover the new behavior.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
e68779f. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Description
Part 5 of 5 replacing #44367. Stacked on #46045.
Activates Portfolio migration when a previously connected wallet enters Buy with Backup & Sync and ramps syncing enabled, then keeps the user in the in-extension Buy flow. The external Portfolio tab remains the fallback only when in-extension ramps are disabled.
Preferred-provider selection now consumes completed synced orders, normalizes
/providers/...identifiers, and re-evaluates an automatically selected default when newer order history arrives. Explicit user selections remain unchanged.Ownership is limited to
@MetaMask/money-movement.Changelog
CHANGELOG entry: Updated Buy to prefer the provider from the latest completed order
Related issues
Depends on #46045.
Works with consensys-vertical-apps/metamask-portfolio#2053.
Replaces the final part of #44367.
Manual testing steps
Pre-merge author checklist
Pre-merge reviewer checklist
Stack: #46042 → #46043 → #46044 → #46045 → #46046