App icon indicating copy to clipboard operation
App copied to clipboard

[$175] Workspace Settings - Error when clicking "ask for admin access" of an existing domain

Open applause-bot[bot] opened this issue 2 weeks ago • 18 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: v9.5.39-2 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/tc/TC-917041 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: All Platforms App Component: Workspace Settings

Action Performed:

Preconditions:

  1. User is logged into an account using a public domain email (e.g., standard personal/testing email).
  2. A managed domain is already configured and verified on the platform (e.g., expplause.com or applause.expensifail.com).

  1. Log into the NewDot application with a public domain account.
  2. Navigate to Workspace > Domains.
  3. Click + New (or Add Domain).
  4. Enter an existing registered domain name (such as expplause.com or applause.expensifail.com) and click Continue.
  5. On the "Domain already set up. Request access" screen, verify that the "Ask for admin access" option is displayed alongside "Never mind".
  6. Click "Ask for admin access".
  7. Observe the application response.

Expected Result:

The admin access request should be submitted successfully without errors, and the user should be taken back to the Domains list.

Actual Result:

An error banner stating "We couldn't send your request. Please try again" is displayed, preventing the user from completing the domain access request.

Workaround:

Unknown

Platforms:

  • [x] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/682c009e-b48f-47bd-a233-1be7a910439e

View all open jobs on GitHub

Applause Internal Information Exported by: Alberto Gutierrez Bug ID: 7313522

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @amyevans

applause-bot[bot] avatar Nov 13 '26 22:11 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/a05a7ec8b11170f1c37fc35b22bef62c46f7dd612d62ce6f60dc40790aac8714

https://platform.applause.com/services/links/v1/external/6ec2d05ad77960672aeca6f6bd49d34e0f82f6914bef1270e5399ece8562eecb

applause-bot[bot] avatar Nov 13 '26 22:11 applause-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (External)

melvin-bot[bot] avatar Nov 13 '26 22:11 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022121374099981106125

melvin-bot[bot] avatar Nov 13 '26 22:11 melvin-bot[bot]

🤖 Web test steps verification results: ❌ fail

Blocked on dev NewDot web: the public-email account requires emailed-code validation before proceeding with the domain. The reported failure could not be reproduced or ruled out.

Account-validation dialog blocking the domain flow
Step Status
Open Workspaces > Domains > New and enter expplause.comNavigated successfully and confirmed the entered domain.
✅
Verify existing-domain actions and request admin accessContinue opened “Validate your account,” requiring an emailed six-digit code unavailable in this run. The existing-domain screen and RequestDomainAdminship response were not reached.

Preliminary analysis — low confidence: The underlying failure remains unconfirmed. The client sends the target domainAccountID and displays the reported message through generic failure handling (Domain.ts:565–590). This does not establish a malformed request or a public-email restriction.

Alternative considered: The UI offers access requests without checking the requester’s email domain (DomainAlreadyExistsPage.tsx:101–112). Whether the server permits this particular requester remains unknown; existing tests mock the API rather than establish eligibility (DomainAlreadyExistsPageTest.tsx:93–126).

Required next evidence: Reproduce with a validated account and capture the failing request’s jsonCode, message and request ID; compare with a same-domain requester. Production-log confirmation was unavailable because this run had no VictoriaLogs access. No code fix is justified yet.
Account-validation dialog blocking the domain flow
❌

view run · view recording

MelvinBot avatar Nov 13 '26 22:11 MelvinBot

Proposal

What is the root cause of that problem?

In src/pages/domain/DomainAlreadyExistsPage.tsx:106-112, clicking "Ask for admin access" executes:

requestDomainAdminship(domainAccountID, currentUserAccountID, !!isTransientDomainEntry);

Inside src/libs/actions/Domain.ts:531-591, requestDomainAdminship dispatches the WRITE_COMMANDS.REQUEST_DOMAIN_ADMINSHIP (RequestDomainAdminship) API call with {domainAccountID}.

When the backend rejects the request (which occurs when an account on a public email domain such as @gmail.com or @applause.com requests admin access to an existing private domain without verified association), the API command enters the failureData rollback pipeline.

In Domain.ts:584, failureData maps the failure directly to:

{
    onyxMethod: Onyx.METHOD.MERGE,
    key: domainErrorsKey,
    value: {requestAdminshipError: getMicroSecondOnyxErrorWithTranslationKey('domain.requestAccessError')},
}

In DomainAlreadyExistsPage.tsx:43:

const [requestError] = useOnyx(`${ONYXKEYS.COLLECTION.DOMAIN_ERRORS}${domainAccountID}`, {selector: (errors) => errors?.requestAdminshipError});

This error is passed into <ConfirmationPage.Content requestErrors={requestError}>, causing ConfirmationPageContent to render FormHelpMessage displaying the generic fallback string domain.requestAccessError ("We couldn't send your request. Please try again."). Furthermore, because requestError is truthy, the navigation effect in DomainAlreadyExistsPage.tsx:62-67 does not call goToDomainsList(), leaving the error banner visible on the screen.

In addition, route param parsing on web routes (workspaces/domain-already-exists/:domainAccountID) in src/libs/Navigation/linkingConfig/config.ts:2354-2357 does not include parse: {domainAccountID: Number}, meaning domainAccountID can be passed as a string depending on navigation entry.

What changes do you think we should make in order to solve the problem?

  1. Sanitize domainAccountID and ensure backend command alignment: In src/pages/domain/DomainAlreadyExistsPage.tsx, ensure domainAccountID is consistently cast as a number:

    const domainAccountID = Number(route.params.domainAccountID);
    

    Add the number parser for WORKSPACES_DOMAIN_ALREADY_EXISTS in src/libs/Navigation/linkingConfig/config.ts:

    [SCREENS.WORKSPACES_DOMAIN_ALREADY_EXISTS]: {
        path: ROUTES.WORKSPACES_DOMAIN_ALREADY_EXISTS.route,
        exact: true,
        parse: {
            domainAccountID: Number,
        },
    },
    
  2. Handle domain requester eligibility or preserve server-returned error feedback: In src/libs/actions/Domain.ts:582-586, when the server rejects RequestDomainAdminship, if the backend provides a specific reason (such as user domain mismatch or validation requirement), allow the server-provided message to take precedence rather than overwriting unconditionally with the generic domain.requestAccessError.

    If Expensify's product architecture dictates that accounts on public email domains (e.g. Gmail) cannot request adminship of private enterprise domains: In DomainAlreadyExistsPage.tsx, check whether the current user's login domain is eligible to request access. If ineligible, disable the primary action and display an instructional note informing the user that admin access requests must originate from an email address matching the managed domain.

What alternative solutions did you explore? (Optional)

We explored suppressing the error banner and navigating back to ROUTES.DOMAINS_LIST optimistically regardless of API outcome; however, this would give users false confirmation that their request succeeded when it was actually rejected by the server.

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 14 '26 00:11 kevinjosh10

Proposal

What is the root cause of that problem?

In src/pages/domain/DomainAlreadyExistsPage.tsx:

const domainAccountID = route.params.domainAccountID;
  1. domainAccountID is passed as a string because src/libs/Navigation/linkingConfig/config.ts configures WORKSPACES_DOMAIN_ALREADY_EXISTS without a parameter parser (parse: {domainAccountID: Number}). When dispatched to requestDomainAdminship, passing a string accountID causes strict type mismatches in Onyx collection error key indexing (${ONYXKEYS.COLLECTION.DOMAIN_ERRORS}${domainAccountID}).
  2. In src/libs/actions/Domain.ts:584, requestDomainAdminship catches backend rejections (such as requesting adminship for a private domain from a public email like @gmail.com) and unconditionally writes a generic fallback error into Onyx:
value: {requestAdminshipError: getMicroSecondOnyxErrorWithTranslationKey('domain.requestAccessError')}

This forces ConfirmationPageContent to render domain.requestAccessError ("We couldn't send your request. Please try again.") without indicating to the user why the request failed (e.g. email domain mismatch).

What changes do you think we should make in order to solve the problem?

  1. In src/libs/Navigation/linkingConfig/config.ts: Add parse: {domainAccountID: Number} to [SCREENS.WORKSPACES_DOMAIN_ALREADY_EXISTS] so domainAccountID is consistently parsed into a number upon navigation.
  2. In src/pages/domain/DomainAlreadyExistsPage.tsx: Ensure domainAccountID is normalized via Number(route.params.domainAccountID) before passing to Onyx subscriptions and requestDomainAdminship.
  3. In src/libs/actions/Domain.ts: In requestDomainAdminship, allow server-returned error feedback in failureData to take precedence if available, rather than overwriting unconditionally with the generic translation key. If the account is on a public domain, disable the request button or provide domain-matching guidance before dispatching the request.
  4. Add unit test coverage in tests/unit/DomainTest.ts verifying parameter parsing and error handling for DomainAlreadyExistsPage.

What alternative solutions did you explore? (Optional)

Silently navigating back to Domains list without checking the request result was considered, but that would falsely lead the user to believe the request succeeded when it was rejected by the server.

jpereyra243-byte avatar Nov 14 '26 01:11 jpereyra243-byte

Proposal

Please re-state the problem that we are trying to solve in this issue.

A public-domain user tries to add a domain someone else already owns. They land on "Domain already set up" and tap Ask for admin access. Instead of being sent back to the Domains list, they get "We couldn't send your request. Please try again." Retrying never helps.

What is the root cause of that problem?

I reproduced this on staging with a gmail account against expplause.com and checked the network response. The client sends a valid request. Auth rejects it:

{
    "jsonCode": 403,
    "message": "403 Cannot request adminship for this domain",
    "source": "auth-via-api",
    "onyxData": []
}

This is the full flow and where it goes wrong:

sequenceDiagram
    participant U as User (public email)
    participant ADP as AddDomainPage
    participant API as Web / Auth
    participant Onyx
    participant DAE as DomainAlreadyExistsPage

    U->>ADP: enter expplause.com, Continue
    ADP->>API: CreateDomain {domainName}
    API-->>Onyx: generic error + form.domainAccountID + minimal domain_<id>
    ADP->>DAE: navigate(domain-already-exists/:id)
    Note over DAE: "Ask for admin access" is always offered,<br/>no eligibility info from CreateDomain
    U->>DAE: Ask for admin access
    DAE->>Onyx: optimistic domain_adminRequesters {me: 'read'}, pending ADD
    DAE->>API: RequestDomainAdminship {domainAccountID}
    API-->>DAE: ❌ 403 "Cannot request adminship for this domain"
    Note over DAE,Onyx: failureData drops the 403 and always writes<br/>'domain.requestAccessError' ("Please try again")
    Onyx-->>DAE: requestError set → stays on page, generic banner

So there are two layers:

  1. Auth refuses the request (403). The payload is fine. {domainAccountID} is the same ID CreateDomain returned, and the request reaches Auth, which rejects it. So either Auth only lets certain accounts request adminship (for example, accounts whose email is on that domain), or that check is wrong. The test case TC-917041 expects this request to succeed for a public-domain account, so Auth and the test case disagree.
  2. The client presents a permanent rejection as something to retry. failureData in requestDomainAdminship (src/libs/actions/Domain.ts) always writes the hard-coded domain.requestAccessError. The 403 gets the same "Please try again" as a network blip, and DomainAlreadyExistsPage keeps offering a button that can never succeed for this user.

The theory raised above, that domainAccountID arrives as a string from the route, isn't the cause. The request reaches Auth with the right ID and gets a deliberate 403.

What changes do you think we should make in order to solve the problem?

First we need someone internal to confirm the intended rule: should a user with a public-domain email be able to request adminship of an existing domain?

If yes (which is what the test case expects): the fix belongs in Auth's adminship-request check, which isn't in this repo, so it needs an internal engineer. On the App side, nothing more is needed beyond the error-handling change below. The existing success path (optimistic domain_adminRequesters, then navigating back to the Domains list) already works once Auth returns 200.

If no (the 403 is intended):

  • Don't show an action that can't succeed. Have CreateDomain's failure response include whether the user is allowed to request adminship, for example a canRequestAdminship flag next to the domainAccountID it already returns. Then DomainAlreadyExistsPage can show only "Never mind", with a short line explaining that someone already set up this domain and to contact its admin.
  • Until that flag exists, handle the 403 explicitly on the client. Show a new message that doesn't offer a retry, for example "You can't request admin access to this domain. Contact one of its admins.", and disable the button after that response so the user isn't encouraged to keep tapping it.

In either case, requestDomainAdminship should stop throwing away the server's answer. Use the response's message when it's there and fall back to domain.requestAccessError only when it isn't, the same way Domain.ts already does around line 346 (response?.message ? response.message : genericError). That way a permission error in this flow never shows up as "please try again" again.

What alternative solutions did you explore? (Optional)

Navigating back to the Domains list on any response, including failures. I dropped this because the user would think a request was sent when Auth actually refused it.

Tests

  • tests/actions/DomainTest.ts: a 403 from RequestDomainAdminship produces the non-retryable error, while a failure with no server message still falls back to domain.requestAccessError.
  • The optimistic domain_adminRequesters[me] entry is rolled back on the 403, and the transient domain entry is removed when isTransientDomainEntry is true.
  • DomainAlreadyExistsPage UI test: after a 403 the button is disabled and the specific message is shown; on a 200 it navigates to the Domains list.

rakesh0x avatar Nov 14 '26 03:11 rakesh0x

📣 @rakesh0x! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 14 '26 03:11 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~018a48e3b960e8c0d2

rakesh0x avatar Nov 14 '26 03:11 rakesh0x

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 14 '26 03:11 melvin-bot[bot]

Looks like a backend issue. requesting internal Engineer to review this issue.

:ribbon: :eyes: :ribbon: C+ reviewed

parasharrajat avatar Nov 14 '26 10:11 parasharrajat

Triggered auto assignment to @amyevans, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] avatar Nov 14 '26 10:11 melvin-bot[bot]

@amyevans, @parasharrajat Whoops! This issue is 2 days overdue. Let's get this updated quick!

@amyevans Huh... This is 4 days overdue. Who can take care of this?

@amyevans 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

@amyevans 10 days overdue. I'm getting more depressed than Marvin.

I confirmed it's from an intentional backend change. Have not had time to address it yet though

amyevans avatar Nov 25 '26 21:11 amyevans

@amyevans @parasharrajat this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!