Skip to content

Change to global environment for all pre-auth uses#21350

Draft
trmartin4 wants to merge 1 commit into
mainfrom
auth/pm-30715/use-global-environment-pre-login
Draft

Change to global environment for all pre-auth uses#21350
trmartin4 wants to merge 1 commit into
mainfrom
auth/pm-30715/use-global-environment-pre-login

Conversation

@trmartin4

@trmartin4 trmartin4 commented Jun 17, 2026

Copy link
Copy Markdown
Member

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-39218

📔 Objective

In #20495, we moved to use the non-user-scoped globalEnvironment$ on the environment selector, to address a race condition on logout that was preventing the correct environment from being used.

We have observed in subsequent tickets that the same issue is now occurring elsewhere in a pre-authenticated state - components and services that execute before the user has authenticated still rely on environment$, and when that is not present (due to the same race condition as #20495) other downstream issues occur.

⚠️ This puts us in a potential foot-gun situation, as subsequent development could re-introduce this at any time. We have follow-up work carved out to replace environment$ with userEnvironment$(userId), which would force by API that a user be present (aka logged in), but until then we are in a position where this could be re-introduced anywhere beyond the pre-auth boundary.

This PR makes the change to globalEnvironment$ in the following places:

  1. Extension, CLI, and desktop SSO login - to determine the correct URL for the redirect to the web vault.
  2. WebAuthn and Duo 2FA - to get the correct web vault URL for the connector URL.
  3. Login with Device - to get the URL for device management web app link.
  4. 2FA component - to get the URL for the 2FA recovery web app link.
  5. Self-hosted environment dialog, to set the values on initialization of the component ❗ This is what is broken in the bug being reported today.
  6. Registration - to determine the correct URL for registration requests.

📸 Screenshots

@sonarqubecloud

Copy link
Copy Markdown

@trmartin4 trmartin4 changed the title Change to global environment for all pre-auth uses. Change to global environment for all pre-auth uses Jun 17, 2026
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 30.43478% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.27%. Comparing base (3a45a88) to head (cce4ad9).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...bs/common/src/auth/services/account-api.service.ts 0.00% 3 Missing ⚠️
libs/auth/src/angular/login/login.component.ts 0.00% 2 Missing ⚠️
libs/auth/src/angular/sso/sso.component.ts 0.00% 2 Missing ⚠️
apps/cli/src/auth/commands/login.command.ts 50.00% 1 Missing ⚠️
...latform/services/sso-localhost-callback.service.ts 0.00% 1 Missing ⚠️
...a-auth-request/login-via-auth-request.component.ts 0.00% 1 Missing ⚠️
...nv-selector/registration-env-selector.component.ts 0.00% 1 Missing ⚠️
...-dialog/self-hosted-env-config-dialog.component.ts 0.00% 1 Missing ⚠️
...uth-webauthn/two-factor-auth-webauthn.component.ts 0.00% 1 Missing ⚠️
...gular/two-factor-auth/two-factor-auth.component.ts 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21350      +/-   ##
==========================================
- Coverage   49.27%   49.27%   -0.01%     
==========================================
  Files        4063     4063              
  Lines      127470   127470              
  Branches    19488    19488              
==========================================
- Hits        62816    62813       -3     
- Misses      60000    60003       +3     
  Partials     4654     4654              

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant