Skip to content

Commit

Permalink
fix: persists query param in redirect urls (appsmithorg#13738)
Browse files Browse the repository at this point in the history
  • Loading branch information
arunvjn committed May 11, 2022
1 parent 8084744 commit ae22baa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,16 @@ describe("Slug URLs", () => {
});
});
});

it("Checks redirect url", () => {
cy.url().then((url) => {
cy.LogOut();
cy.visit(url + "?embed=true&a=b");
cy.location().should((loc) => {
expect(loc.search).to.eq(
`?redirectUrl=${encodeURIComponent(url + "?embed=true&a=b")}`,
);
});
});
});
});
18 changes: 12 additions & 6 deletions app/client/src/pages/AppViewer/PrimaryCTA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type Props = {
* COMPONENT
* ---------------------------------------------------------------------------------------------------
*/
const LOGIN_URL = `${AUTH_LOGIN_URL}?redirectUrl=${window.location.href}`;

function PrimaryCTA(props: Props) {
const { className, url } = props;
Expand All @@ -56,13 +55,20 @@ function PrimaryCTA(props: Props) {

// get the fork url
const forkURL = useMemo(() => {
return `${LOGIN_URL}?redirectUrl=${window.location.origin}${viewerURL({
applicationId: currentApplication?.applicationId,
pageId: currentPageID,
suffix: "fork",
})}`;
const encodedForkRedirectURL = `${encodeURIComponent(
`${window.location.origin}${viewerURL({
applicationId: currentApplication?.applicationId,
pageId: currentPageID,
suffix: "fork",
})}`,
)}`;
return `${AUTH_LOGIN_URL}?redirectUrl=${encodedForkRedirectURL}`;
}, [currentApplication?.applicationId, currentPageID]);

const LOGIN_URL = `${AUTH_LOGIN_URL}?redirectUrl=${encodeURIComponent(
window.location.href,
)}`;

/**
* returns the cta to be used based on user login status
*
Expand Down
4 changes: 3 additions & 1 deletion app/client/src/sagas/ErrorSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ function* safeCrashSagaRequest(action: ReduxAction<{ code?: string }>) {
get(user, "email") === ANONYMOUS_USERNAME &&
code === ERROR_CODES.PAGE_NOT_FOUND
) {
window.location.href = `${AUTH_LOGIN_URL}?redirectUrl=${window.location.href}`;
window.location.href = `${AUTH_LOGIN_URL}?redirectUrl=${encodeURIComponent(
window.location.href,
)}`;

return false;
}
Expand Down

0 comments on commit ae22baa

Please sign in to comment.