Skip to content

Don't persist My Domain when using Welcome/Discovery login#4046

Merged
sfdctaka merged 1 commit into
forcedotcom:devfrom
sfdctaka:dontAddMyDomain
May 29, 2026
Merged

Don't persist My Domain when using Welcome/Discovery login#4046
sfdctaka merged 1 commit into
forcedotcom:devfrom
sfdctaka:dontAddMyDomain

Conversation

@sfdctaka
Copy link
Copy Markdown
Contributor

Summary

When an app uses a Welcome/Discovery domain (e.g., welcome.salesforce.com/discovery) as its login host, the domain discovery flow resolves the user's My Domain and passes it to handleCustomDomainUpdateWithLoginHint:. Previously, this called setLoginHost:, which persisted the My Domain into SFSDKLoginHostStorage and NSUserDefaults. This caused two problems:

  1. The server picker list got polluted with My Domain entries
  2. After logout, the login screen showed the My Domain instead of returning to the Welcome/Discovery page

Changes

  • SFOAuthCoordinator: Remove setLoginHost: call from handleCustomDomainUpdateWithLoginHint:loginHint:credentials.domain is sufficient for the auth flow and doesn't pollute persistent storage.
  • SFUserAccountManager: Skip overwriting loginHost with credentials.domain when the current login host is a discovery domain (checked via DomainDiscoveryCoordinator.isDiscoveryDomain:).
  • WelcomeDiscoveryLoginHostTests: Add tests covering isDiscoveryDomain logic, login host preservation after setting current user, and verifying storage isn't polluted.

Test Plan

  • Unit tests pass (WelcomeDiscoveryLoginHostTests)
  • Configure app with Welcome/Discovery domain → log in → verify login host remains discovery domain
  • Log out → verify login screen returns to Welcome/Discovery page (not My Domain)
  • Verify server picker does not accumulate My Domain entries after repeated login/logout cycles
  • Verify non-discovery login flow still updates login host normally (regression check)

@github-actions
Copy link
Copy Markdown

1 Warning
⚠️ Static Analysis found an issue with one or more files you modified. Please fix the issue(s).

Clang Static Analysis Issues

File Type Category Description Line Col
SFOAuthCoordinator Nullability Memory error nil assigned to a pointer which is expected to have non-null value 119 19
SFOAuthCoordinator Nullability Memory error nil assigned to a pointer which is expected to have non-null value 243 15
SFUserAccountManager Nullability Memory error Null passed to a callee that requires a non-null 2nd parameter 1579 15
SFUserAccountManager Nullability Memory error Null passed to a callee that requires a non-null 2nd parameter 1594 15
SFUserAccountManager Nullability Memory error nil passed to a callee that requires a non-null 2nd parameter 2232 13

Generated by 🚫 Danger

@github-actions
Copy link
Copy Markdown

TestsPassed ☑️SkippedFailed ❌️
SalesforceSDKCore iOS ^26 Test Results638 ran636 ✅2 ❌
TestResult
SalesforceSDKCore iOS ^26 Test Results
SFSDKAuthConfigUtilTests.testBrowserBasedLoginEnabled❌ failure
SFUserAccountManagerTests.testUserAccountEncoding❌ failure

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.20%. Comparing base (36f6bf6) to head (2459542).
⚠️ Report is 8 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #4046      +/-   ##
==========================================
- Coverage   70.61%   68.20%   -2.42%     
==========================================
  Files         245      245              
  Lines       21461    21461              
==========================================
- Hits        15155    14637     -518     
- Misses       6306     6824     +518     
Components Coverage Δ
Analytics 70.78% <ø> (ø)
Common 70.69% <ø> (-0.19%) ⬇️
Core 61.66% <100.00%> (-3.74%) ⬇️
SmartStore 73.44% <ø> (ø)
MobileSync 88.79% <ø> (ø)
Files with missing lines Coverage Δ
...lesforceSDKCore/Classes/OAuth/SFOAuthCoordinator.m 51.58% <ø> (-10.92%) ⬇️
...SDKCore/Classes/UserAccount/SFUserAccountManager.m 54.75% <100.00%> (-7.38%) ⬇️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

TestsPassed ✅SkippedFailed
AuthFlowTester UI Test Results all1 ran1 ✅
TestResult
No test annotations available

@github-actions
Copy link
Copy Markdown

TestsPassed ☑️SkippedFailed ❌️
SalesforceSDKCore iOS ^18 Test Results638 ran636 ✅2 ❌
TestResult
SalesforceSDKCore iOS ^18 Test Results
testMissingMyDomain()❌ failure
SFSDKAuthConfigUtilTests.testBrowserBasedLoginEnabled❌ failure

if (user.credentials.domain && !isNativeLogin)
// Also skip if the app uses a Welcome/Discovery domain — persisting the My Domain
// would pollute the server picker and prevent returning to the discovery page on logout.
BOOL isDiscoveryLogin = [[[SFDomainDiscoveryCoordinator alloc] init] isDiscoveryDomain:self.loginHost];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice finding a simple check!

@brandonpage
Copy link
Copy Markdown
Contributor

LGTM, but before I approve I would like to know how/where the correct (My Domain) url gets saved on the user when they login with Welcome.

@sfdctaka
Copy link
Copy Markdown
Contributor Author

LGTM, but before I approve I would like to know how/where the correct (My Domain) url gets saved on the user when they login with Welcome.

@brandonpage In line 870, self.credentials.domain = myDomain; of handleCustomDomainUpdateWithLoginHint:myDomain:, SFOAuthCoordinator holds onto self.credentials from start to finish. When domain discovery resolves mycompany.my.salesforce.com, it's written directly onto that credentials object.

When [self authenticate] is called immediately after, it reads credentials.domain to construct https://mycompany.my.salesforce.com/services/oauth2/authorize?..... No global loginHost needed.

After auth completes, finalizeAuthCompletion: → applyCredentials:withIdData: assigns authSession.oauthCoordinator.credentials (which still carries domain = mycompany.my.salesforce.com) to the user account, then calls saveAccountForUser: which archives it via NSCoding.

@sfdctaka sfdctaka merged commit c0c3f5a into forcedotcom:dev May 29, 2026
24 of 30 checks passed
@sfdctaka sfdctaka deleted the dontAddMyDomain branch May 29, 2026 19:07
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.

4 participants