fix: logout user if the session has expired between page switches (#40718)

## Description
If a user's session times out and the user navigates to a new page in an
application the user was not navigated to the login page. This change
makes sure that the user profile is updated in the redux store on page
change and the page response is validated using the response
interceptors.

This bug was introduced in [this
PR](https://github.com/appsmithorg/appsmith/pull/36096).

Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.All"

### 🔍 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/15155628540>
> Commit: a3349cda620d3af78d2604f9edea151f6f15408e
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=15155628540&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 21 May 2025 08:31:39 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 error handling when loading published page resources,
ensuring better management of API errors and user profile updates.
- **Refactor**
- Updated internal handling of API response error codes for consistency.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Diljit 2025-05-21 16:32:19 +05:30 committed by GitHub
parent fa4df44670
commit f0b01827f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 7 deletions

View File

@ -1,5 +1,5 @@
export interface APIResponseError {
code: string | number;
code: string;
message: string;
errorType?: string;
}

View File

@ -150,6 +150,10 @@ import {
} from "selectors/gitModSelectors";
import { appsmithTelemetry } from "instrumentation";
import { getLayoutSavePayload } from "ee/sagas/helpers";
import { apiFailureResponseInterceptor } from "api/interceptors/response";
import type { AxiosError } from "axios";
import { handleFetchApplicationError } from "./ApplicationSagas";
import { getCurrentUser } from "actions/authActions";
export interface HandleWidgetNameUpdatePayload {
newName: string;
@ -421,13 +425,30 @@ export function* fetchPublishedPageResourcesSaga(
// We need to recall consolidated view API in order to fetch actions when page is switched
// As in the first call only actions of the current page are fetched
// In future, we can reuse this saga to fetch other resources of the page like actionCollections etc
const { publishedActions } = response;
const { pageWithMigratedDsl, publishedActions, userProfile } = response;
yield call(
postFetchedPublishedPage,
response.pageWithMigratedDsl,
pageId,
);
// Update the current user in the redux store. If the session has expired between page switch, the user profile will be updated
yield put(getCurrentUser(userProfile));
// If the pageWithMigratedDsl has an error, we need to intercept the error and return
// This makes sure that the user is navigated to the login page if page is not found
if (pageWithMigratedDsl?.responseMeta?.error) {
const { responseMeta } = pageWithMigratedDsl;
const { status } = responseMeta;
// apiFailureResponseInterceptor throws an error if the response is not valid
// this error needs to be caught and handled by handleFetchApplicationError
yield apiFailureResponseInterceptor({
response: {
data: {
responseMeta,
},
status,
},
} as AxiosError<ApiResponse>);
}
yield call(postFetchedPublishedPage, pageWithMigratedDsl, pageId);
// NOTE: fetchActionsForView is used here to update publishedActions in redux store and not to fetch actions again
yield put(fetchActionsForView({ applicationId: "", publishedActions }));
@ -437,6 +458,8 @@ export function* fetchPublishedPageResourcesSaga(
});
}
} catch (error) {
// Handle the error thrown by apiFailureResponseInterceptor
yield call(handleFetchApplicationError, error);
yield put({
type: ReduxActionErrorTypes.FETCH_PUBLISHED_PAGE_RESOURCES_ERROR,
payload: {