Skip to content
Snippets Groups Projects
Unverified Commit 56c70724 authored by Ryan Laurie's avatar Ryan Laurie Committed by GitHub
Browse files

observe redirect param even when logged in (#37750)

parent 45a03e00
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,13 @@ export const createSessionMiddleware = (
let wasLoggedIn = getIsLoggedIn();
// get the redirect url before refreshing the session because after the refresh the url will be reset
const redirectUrl = getRedirectUrl();
if (wasLoggedIn && !!redirectUrl) {
store.dispatch(replace(redirectUrl));
}
intervalId = setInterval(async () => {
const isLoggedIn = getIsLoggedIn();
......@@ -35,8 +42,6 @@ export const createSessionMiddleware = (
wasLoggedIn = isLoggedIn;
if (isLoggedIn) {
// get the redirect url before refreshing the session because after the refresh the url will be reset
const redirectUrl = getRedirectUrl();
await store.dispatch(refreshSession())?.unwrap();
if (redirectUrl !== null) {
......
......@@ -116,6 +116,29 @@ describe("createSessionMiddleware", () => {
});
});
describe("logged in redirect", () => {
beforeEach(() => {
changeJSDOMURL(
"https://metabase.com/auth/login?redirect=%2Fquestion%2F1%3Fquery%3D5%23hash",
);
});
it("should redirect to the redirectUrl", async () => {
Cookie.get = jest
.fn()
.mockImplementationOnce(() => "alive")
.mockImplementationOnce(() => "alive");
const { handleAction, dispatchMock } = setup();
handleAction(actionStub);
clock.tick(COOKIE_POOLING_TIMEOUT);
expect(dispatchMock).toHaveBeenCalled();
expect(replace).toHaveBeenCalledWith("/question/1?query=5#hash");
});
});
describe("when not logged in", () => {
beforeEach(() => {
changeJSDOMURL(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment