From 5ce59d0352ba5402452bb812ac0e506b3c2216df Mon Sep 17 00:00:00 2001 From: Alican Erdurmaz Date: Tue, 17 Dec 2024 16:36:16 +0300 Subject: [PATCH] fix(core): doesnt redirect to query param after login (#6583) --- .changeset/great-hotels-admire.md | 18 ++++++++++++++++++ cypress/e2e/auth-antd/all.cy.ts | 6 +++--- cypress/e2e/auth-chakra-ui/all.cy.ts | 2 +- cypress/e2e/auth-mantine/all.cy.ts | 2 +- cypress/e2e/auth-material-ui/all.cy.ts | 2 +- .../table-material-ui-advanced/data-grid.cy.ts | 10 ++++++++-- cypress/e2e/with-nextjs/all.cy.ts | 3 +-- cypress/e2e/with-remix-antd/all.cy.ts | 8 ++++---- cypress/e2e/with-remix-headless/all.cy.ts | 8 ++++---- cypress/e2e/with-remix-vite-headless/all.cy.ts | 8 ++++---- packages/core/src/hooks/auth/useLogin/index.ts | 8 ++++++-- 11 files changed, 51 insertions(+), 24 deletions(-) create mode 100644 .changeset/great-hotels-admire.md diff --git a/.changeset/great-hotels-admire.md b/.changeset/great-hotels-admire.md new file mode 100644 index 000000000000..b87d5b4d6cf2 --- /dev/null +++ b/.changeset/great-hotels-admire.md @@ -0,0 +1,18 @@ +--- +"@refinedev/core": patch +--- + +fixed: `to` query parameter is not working after login. #6582 +From now on, the `to` query parameter will work after login. If the URL includes a `to` query parameter, the user will be redirected to the specified path after logging in. + +Example: + +After logout, Refine will automatically appends `to` query param to URL. + +``` +http://localhost:3000/login?to=/any-path +``` + +After login, it will redirect to `http://localhost:3000/any-path` + +Resolves [#6582](https://github.com/refinedev/refine/issues/6582) diff --git a/cypress/e2e/auth-antd/all.cy.ts b/cypress/e2e/auth-antd/all.cy.ts index 698c10079843..243671d50405 100644 --- a/cypress/e2e/auth-antd/all.cy.ts +++ b/cypress/e2e/auth-antd/all.cy.ts @@ -25,7 +25,7 @@ describe("auth-antd", () => { }; describe("login", () => { - it.skip("should login", () => { + it("should login", () => { login(); cy.location("pathname").should("eq", "/"); @@ -42,7 +42,7 @@ describe("auth-antd", () => { cy.location("pathname").should("eq", "/login"); }); - it.skip("should has 'to' param on URL after redirected to /login", () => { + it("should has 'to' param on URL after redirected to /login", () => { login(); cy.location("pathname").should("eq", "/"); @@ -68,7 +68,7 @@ describe("auth-antd", () => { }); describe("register", () => { - it.skip("should register", () => { + it("should register", () => { cy.get("a") .contains(/sign up/i) .click(); diff --git a/cypress/e2e/auth-chakra-ui/all.cy.ts b/cypress/e2e/auth-chakra-ui/all.cy.ts index 7b6ab63c48cd..094489616705 100644 --- a/cypress/e2e/auth-chakra-ui/all.cy.ts +++ b/cypress/e2e/auth-chakra-ui/all.cy.ts @@ -40,7 +40,7 @@ describe("auth-chakra-ui", () => { cy.location("pathname").should("eq", "/login"); }); - it.skip("should has 'to' param on URL after redirected to /login", () => { + it("should has 'to' param on URL after redirected to /login", () => { login(); cy.location("pathname").should("eq", "/posts"); diff --git a/cypress/e2e/auth-mantine/all.cy.ts b/cypress/e2e/auth-mantine/all.cy.ts index ce797bf924a3..369807770707 100644 --- a/cypress/e2e/auth-mantine/all.cy.ts +++ b/cypress/e2e/auth-mantine/all.cy.ts @@ -39,7 +39,7 @@ describe("auth-mantine", () => { cy.location("pathname").should("eq", "/login"); }); - it.skip("should has 'to' param on URL after redirected to /login", () => { + it("should has 'to' param on URL after redirected to /login", () => { login(); cy.location("pathname").should("eq", "/posts"); diff --git a/cypress/e2e/auth-material-ui/all.cy.ts b/cypress/e2e/auth-material-ui/all.cy.ts index dd1c1ae0a967..2d2a8e735194 100644 --- a/cypress/e2e/auth-material-ui/all.cy.ts +++ b/cypress/e2e/auth-material-ui/all.cy.ts @@ -41,7 +41,7 @@ describe("auth-material-ui", () => { cy.location("pathname").should("eq", "/login"); }); - it.skip("should has 'to' param on URL after redirected to /login", () => { + it("should has 'to' param on URL after redirected to /login", () => { login(); cy.location("pathname").should("eq", "/posts"); diff --git a/cypress/e2e/table-material-ui-advanced/data-grid.cy.ts b/cypress/e2e/table-material-ui-advanced/data-grid.cy.ts index 62a5152cfa5d..f0c67174c3c8 100644 --- a/cypress/e2e/table-material-ui-advanced/data-grid.cy.ts +++ b/cypress/e2e/table-material-ui-advanced/data-grid.cy.ts @@ -7,16 +7,22 @@ describe("table-material-ui-advanced", () => { }); it("should work with filter", () => { - // wait for loading + // wait for requests cy.wait("@getPosts"); + cy.wait("@getCategories"); + // wait for loadings cy.getMaterialUILoadingCircular().should("not.exist"); + cy.get("[data-field='category.id']").should("have.length", 16); + cy.get("[data-field='category.id']").should("not.contain", "Loading..."); // open the column menu of title cy.getMaterialUIColumnHeader(2).within(() => cy.get(".MuiDataGrid-menuIcon > button").click({ force: true }), ); // click the filter menu item - cy.get(".MuiDataGrid-menu > div > .MuiList-root").children().eq(3).click(); + cy.get(".MuiDataGrid-menu > div > .MuiList-root").children().eq(3).click({ + force: true, + }); // type the filter value cy.get("[placeholder='Filter value']").type("lorem"); // url should contain the filter diff --git a/cypress/e2e/with-nextjs/all.cy.ts b/cypress/e2e/with-nextjs/all.cy.ts index cb260ecf0cbc..096c1411dfee 100644 --- a/cypress/e2e/with-nextjs/all.cy.ts +++ b/cypress/e2e/with-nextjs/all.cy.ts @@ -77,8 +77,7 @@ describe("with-nextjs", () => { cy.location("pathname").should("eq", "/login"); }); - // Not working on React Server Components - it.skip("should has 'to' param on URL after redirected to /login", () => { + it("should has 'to' param on URL after redirected to /login", () => { login(); cy.location("pathname").should("eq", "/"); diff --git a/cypress/e2e/with-remix-antd/all.cy.ts b/cypress/e2e/with-remix-antd/all.cy.ts index e5724049e6bc..3236db5f0684 100644 --- a/cypress/e2e/with-remix-antd/all.cy.ts +++ b/cypress/e2e/with-remix-antd/all.cy.ts @@ -197,7 +197,7 @@ describe.skip("with-remix-antd", () => { }); }); - it.skip("should edit record", () => { + it("should edit record", () => { cy.getEditButton().first().click(); // wait loading state and render to be finished @@ -214,7 +214,7 @@ describe.skip("with-remix-antd", () => { }); }); - it.skip("should delete record", () => { + it("should delete record", () => { cy.getEditButton().first().click(); // wait loading state and render to be finished @@ -255,7 +255,7 @@ describe.skip("with-remix-antd", () => { cy.getAntdFormItemError({ id: "status" }).should("not.exist"); }); - it.skip("should edit form render errors", () => { + it("should edit form render errors", () => { cy.getEditButton().first().click(); // wait loading state and render to be finished @@ -283,7 +283,7 @@ describe.skip("with-remix-antd", () => { }); }); - it.skip("should edit form warn when unsaved changes", () => { + it("should edit form warn when unsaved changes", () => { cy.wait("@getPosts"); cy.getEditButton().first().click(); diff --git a/cypress/e2e/with-remix-headless/all.cy.ts b/cypress/e2e/with-remix-headless/all.cy.ts index 64cbce8e22ba..2a8b510980b7 100644 --- a/cypress/e2e/with-remix-headless/all.cy.ts +++ b/cypress/e2e/with-remix-headless/all.cy.ts @@ -28,7 +28,7 @@ describe("with-remix-headless", () => { }); describe("login", () => { - it.skip("should login", () => { + it("should login", () => { login(); cy.location("pathname").should("eq", "/posts"); cy.getAllCookies().then((cookies) => { @@ -36,7 +36,7 @@ describe("with-remix-headless", () => { }); }); - it.skip("should has 'to' param on URL after redirected to /login", () => { + it("should has 'to' param on URL after redirected to /login", () => { login(); cy.location("pathname").should("eq", "/posts"); @@ -60,7 +60,7 @@ describe("with-remix-headless", () => { }); describe("register", () => { - it.skip("should register", () => { + it("should register", () => { cy.get("a") .contains(/sign up/i) .click(); @@ -74,7 +74,7 @@ describe("with-remix-headless", () => { }); describe("logout", () => { - it.skip("should logout", () => { + it("should logout", () => { login(); cy.get("button") .contains(/logout/i) diff --git a/cypress/e2e/with-remix-vite-headless/all.cy.ts b/cypress/e2e/with-remix-vite-headless/all.cy.ts index 0434a5954873..9ab1b0e825be 100644 --- a/cypress/e2e/with-remix-vite-headless/all.cy.ts +++ b/cypress/e2e/with-remix-vite-headless/all.cy.ts @@ -28,7 +28,7 @@ describe("with-remix-vite-headless", () => { }); describe("login", () => { - it.skip("should login", () => { + it("should login", () => { login(); cy.location("pathname").should("eq", "/posts"); cy.getAllCookies().then((cookies) => { @@ -36,7 +36,7 @@ describe("with-remix-vite-headless", () => { }); }); - it.skip("should has 'to' param on URL after redirected to /login", () => { + it("should has 'to' param on URL after redirected to /login", () => { login(); cy.location("pathname").should("eq", "/posts"); @@ -60,7 +60,7 @@ describe("with-remix-vite-headless", () => { }); describe("register", () => { - it.skip("should register", () => { + it("should register", () => { cy.get("a") .contains(/sign up/i) .click(); @@ -74,7 +74,7 @@ describe("with-remix-vite-headless", () => { }); describe("logout", () => { - it.skip("should logout", () => { + it("should logout", () => { login(); cy.get("button") .contains(/logout/i) diff --git a/packages/core/src/hooks/auth/useLogin/index.ts b/packages/core/src/hooks/auth/useLogin/index.ts index 4c7740285ee1..3a64de40b56a 100644 --- a/packages/core/src/hooks/auth/useLogin/index.ts +++ b/packages/core/src/hooks/auth/useLogin/index.ts @@ -175,7 +175,9 @@ export function useLogin({ } } - await invalidateAuthStore(); + setTimeout(() => { + invalidateAuthStore(); + }, 32); }, onError: (error: any) => { open?.(buildNotification(error)); @@ -219,7 +221,9 @@ export function useLogin({ } } - await invalidateAuthStore(); + setTimeout(() => { + invalidateAuthStore(); + }, 32); close?.("login-error"); },