From 3d7a99e922aafa9c82ba7d9364741a531e884b77 Mon Sep 17 00:00:00 2001 From: Jacques Ikot Date: Wed, 4 Jun 2025 14:02:30 +0100 Subject: [PATCH] fix: handle undefined user object in LandingScreen for non-existent cloud billing domains (#40855) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 ; } else { return ; } } ``` **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 ; } else { return ; } } ``` ### 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" ### :mag: Cypress test results > [!TIP] > ๐ŸŸข ๐ŸŸข ๐ŸŸข All cypress tests have passed! ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ > Workflow run: > Commit: afee6b1b89b3bf2c65290a1cef9355e72c1ab14e > Cypress dashboard. > Tags: `@tag.Authentication, @tag.Sanity` > Spec: >
Wed, 04 Jun 2025 10:09:08 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **Bug Fixes** - Improved user redirection on the landing screen to ensure users are correctly routed based on their authentication status. --- app/client/src/LandingScreen.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/client/src/LandingScreen.tsx b/app/client/src/LandingScreen.tsx index 6762b1dcf4..41d2f720b8 100755 --- a/app/client/src/LandingScreen.tsx +++ b/app/client/src/LandingScreen.tsx @@ -15,8 +15,8 @@ interface Props { } function LandingScreen(props: Props) { - if (props.user && window.location.pathname === BASE_URL) { - if (props.user.email === ANONYMOUS_USERNAME) { + if (window.location.pathname === BASE_URL) { + if (!props.user || props.user.email === ANONYMOUS_USERNAME) { return ; } else { return ;