Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/client/src/pages/UserAuth/VerifyUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const VerifyUser = (
email: string;
token: string;
redirectUrl: string;
organizationId: string;
}>,
) => {
const queryParams = new URLSearchParams(props.location.search);
Expand Down
10 changes: 10 additions & 0 deletions app/client/src/sagas/InitSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import {
import type { ApplicationPayload } from "entities/Application";
import type { Page } from "entities/Page";
import type { PACKAGE_PULL_STATUS } from "ee/constants/ModuleConstants";
import { validateSessionToken } from "utils/SessionUtils";

export const URL_CHANGE_ACTIONS = [
ReduxActionTypes.CURRENT_APPLICATION_NAME_UPDATE,
Expand Down Expand Up @@ -462,6 +463,15 @@ function* appEngineSaga(action: ReduxAction<AppEnginePayload>) {
}

function* eagerPageInitSaga() {
try {
// Validate session token if present
yield call(validateSessionToken);
} catch (error) {
// Log error but don't block the rest of the initialization
log.error("Error validating session token:", error);
Sentry.captureException(error);
}

const url = window.location.pathname;
const search = window.location.search;

Expand Down
42 changes: 42 additions & 0 deletions app/client/src/utils/SessionUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Api from "api/Api";
import type { ApiResponse } from "api/types";

export const SESSION_TOKEN_PARAM = "sessionToken";

/**
* Validates a session token from the URL and sets up the session.
* This is used during cross-domain session transfers.
*
* @returns A promise that resolves to true if the session was validated successfully
*/
export const validateSessionToken = async (): Promise<boolean> => {
try {
const urlParams = new URLSearchParams(window.location.search);
const sessionToken = urlParams.get("sessionToken");

if (!sessionToken) {
return false;
}

// Get the response from the API
const response = (await Api.get(
`v1/session/validate?sessionToken=${sessionToken}`,
)) as unknown as ApiResponse<boolean>;

// Check if the request was successful
if (!response?.responseMeta?.success) {
return false;
}

// Remove the session token from the URL
const url = new URL(window.location.href);

url.searchParams.delete("sessionToken");
window.history.replaceState({}, "", url.toString());

// The data field contains the boolean result directly
return !!response.data;
} catch (error) {
return false;
}
};
Loading