Skip to content

Commit 9ea0ba4

Browse files
authored
Fix redirect urls when api gateway is enabled (#2697)
1 parent f1dccca commit 9ea0ba4

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

frontend/public/src/lib/auth.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export const generateLoginRedirectUrl = () => {
5858
const { pathname, search, hash } = window.location
5959

6060
const next = `${pathname}${search}${hash}`
61+
62+
if (SETTINGS.api_gateway_enabled) {
63+
window.location = `/login/?${qs.stringify({ next })}`
64+
return
65+
}
6166
return `${routes.login.begin}?${qs.stringify({ next })}`
6267
}
6368

frontend/public/src/lib/auth_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ describe("auth lib function", () => {
2323
)
2424
})
2525

26+
it("generateLoginRedirectUrl should set window.location to /login/ w/ a redirect url", () => {
27+
global.SETTINGS = {
28+
api_gateway_enabled: true
29+
}
30+
window.location = "/protected/route?var=abc"
31+
generateLoginRedirectUrl()
32+
assert.equal(
33+
window.location.toString(),
34+
"http://fake/login/?next=%2Fprotected%2Froute%3Fvar%3Dabc"
35+
)
36+
})
37+
2638
describe("handleAuthResponse", () => {
2739
let history, sandbox
2840

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export default function LoginPage() {
2-
const sign_in_url = (new URL(DATASOURCES_CONFIG.mitxOnline)).origin + "/signin/?next=/staff-dashboard/";
2+
const sign_in_url =
3+
new URL(DATASOURCES_CONFIG.mitxOnline).origin +
4+
"/signin/?next=/staff-dashboard/";
35

4-
document.location = sign_in_url;
6+
document.location = sign_in_url;
57

6-
return (<>Please wait while we redirect you to the sign in page...</>);
7-
8-
};
8+
return <>Please wait while we redirect you to the sign in page...</>;
9+
}

0 commit comments

Comments
 (0)