PromucFlow_constructor/app/client
Jacques Ikot 3d7a99e922
fix: handle undefined user object in LandingScreen for non-existent cloud billing domains (#40855)
## Problem

With the introduction of cloud billing and multi-organization support,
users can now access Appsmith through organization-specific subdomains
(e.g., `testorg.appsmith.com`). However, when users attempt to access
non-existent domains (e.g., `domaindoesnotexist.appsmith.com`), the
system fails to return a user object, causing the application to get
stuck in an infinite loading state.

## 🔍 Root Cause

The issue was in the `LandingScreen` component's conditional logic:

```tsx
// Previous implementation 
if (props.user && window.location.pathname === BASE_URL) {
  if (props.user.email === ANONYMOUS_USERNAME) {
    return <Redirect to={AUTH_LOGIN_URL} />;
  } else {
    return <Redirect to={APPLICATIONS_URL} />;
  }
}
```

**The problem:** When accessing a non-existent domain, `props.user` is
`null`/`undefined`, causing the condition `props.user &&
window.location.pathname === BASE_URL` to evaluate to `false`. This
prevented the redirect logic from executing, leaving users on a
perpetual loading screen instead of being properly redirected to the
login page.

##  Solution

Updated the conditional logic to handle cases where the user object is
undefined:

```tsx
// Fixed implementation 
if (window.location.pathname === BASE_URL) {
  if (!props.user || props.user.email === ANONYMOUS_USERNAME) {
    return <Redirect to={AUTH_LOGIN_URL} />;
  } else {
    return <Redirect to={APPLICATIONS_URL} />;
  }
}
```

### Key changes:
1. **Removed the `props.user &&` guard condition** - Now the redirect
logic always executes when on the base URL
2. **Added explicit null/undefined check** - The condition `!props.user
|| props.user.email === ANONYMOUS_USERNAME` properly handles both
scenarios:
   - When no user object exists (non-existent domains)
   - When the user is anonymous

## 📊 Impact

| Scenario | Before | After |
|----------|---------|-------|
| Valid org domain + authenticated user |  Redirects to applications |
 Redirects to applications |
| Valid org domain + anonymous user |  Redirects to login |  Redirects
to login |
| **Non-existent org domain** |  **Infinite loading screen** | 
**Redirects to login** |
| Direct access to login URL |  Works as expected |  Works as expected
|

## 🧪 Testing Scenarios

This fix addresses the following scenarios in the cloud billing
multi-org environment:

- [x] Valid organization domain with authenticated user → Redirects to
applications
- [x] Valid organization domain with anonymous user → Redirects to login
- [x] **Non-existent organization domain → Redirects to login (instead
of infinite loading)**
- [x] Direct access to login URL → Works as expected

## Automation

/ok-to-test tags="@tag.Authentication, @tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/15438685266>
> Commit: afee6b1b89b3bf2c65290a1cef9355e72c1ab14e
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=15438685266&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Authentication, @tag.Sanity`
> Spec:
> <hr>Wed, 04 Jun 2025 10:09:08 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved user redirection on the landing screen to ensure users are
correctly routed based on their authentication status.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-06-04 06:02:30 -07:00
..
.husky chore: adds depandabot.yml (#40521) 2025-05-01 05:44:04 +00:00
.yarn
config fix: sourcemaps (#39301) 2025-02-16 20:05:50 +03:00
cypress chore: skipped asserting evaluated value with generated query body (#40854) 2025-06-04 11:58:17 +05:30
docker/templates chore: add grafana faro sdk (CE) (#38301) 2024-12-26 10:37:41 +05:30
generators
packages fix: Incorrect display of values in table computed value (#40664) 2025-06-02 14:56:28 +05:30
public chore: add maximum-scale to avoid zoom on inputs in iOS (#40171) 2025-04-08 19:16:31 +05:30
scripts chore: Eject CRA (#39264) 2025-02-14 14:24:41 +05:30
src fix: handle undefined user object in LandingScreen for non-existent cloud billing domains (#40855) 2025-06-04 06:02:30 -07:00
test chore: added automatic option to run behaviour behind feature flag (#40608) 2025-05-16 16:29:31 +05:30
typings
.babelrc chore: Eject CRA (#39264) 2025-02-14 14:24:41 +05:30
.dockerignore
.editorconfig
.eslintrc.base.json
.eslintrc.js
.fork-ts-checkerrc
.gitignore
.lintstagedrc.json chore: update import of AppState to DefaultReduxState (#40494) 2025-05-01 15:53:37 +05:30
.nvmrc
.prettierignore
.prettierrc
.sentryclirc
.yarnrc.yml
build.sh fix: sourcemaps (#39301) 2025-02-16 20:05:50 +03:00
cypress_ci_custom.config.ts
cypress_ci_hosted.config.ts
cypress_ci.config.ts
cypress-add-tags.js
cypress.config.ts
download-assets.js
jest.config.js chore: add grafana faro sdk (CE) (#38301) 2024-12-26 10:37:41 +05:30
knip.json chore: Eject CRA (#39264) 2025-02-14 14:24:41 +05:30
package.json chore: update import of AppState to DefaultReduxState (#40494) 2025-05-01 15:53:37 +05:30
README.md
README.old.md
start-caddy.sh
start-https.sh chore: convert consolidated api etag to a weak one (#38939) 2025-01-31 16:35:20 +05:30
tailwind.config.js
tsconfig.json
tsconfig.path.json
vercel.json
yarn.lock chore: downgrade tinymce from 7.7.1 to 6.8.3 in package.json (#40465) 2025-04-29 10:24:01 +05:30

Appsmith Client

This project was bootstrapped with Create React App.

For details on setting up your development machine, please refer to the Setup Guide