Skip to content

Commit

Permalink
fix(core): doesnt redirect to query param after login (#6583)
Browse files Browse the repository at this point in the history
  • Loading branch information
alicanerdurmaz authored Dec 17, 2024
1 parent 8fbaae8 commit 5ce59d0
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 24 deletions.
18 changes: 18 additions & 0 deletions .changeset/great-hotels-admire.md
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions cypress/e2e/auth-antd/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("auth-antd", () => {
};

describe("login", () => {
it.skip("should login", () => {
it("should login", () => {
login();

cy.location("pathname").should("eq", "/");
Expand All @@ -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", "/");

Expand All @@ -68,7 +68,7 @@ describe("auth-antd", () => {
});

describe("register", () => {
it.skip("should register", () => {
it("should register", () => {
cy.get("a")
.contains(/sign up/i)
.click();
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/auth-chakra-ui/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/auth-mantine/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/auth-material-ui/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
10 changes: 8 additions & 2 deletions cypress/e2e/table-material-ui-advanced/data-grid.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions cypress/e2e/with-nextjs/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", "/");

Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/with-remix-antd/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/with-remix-headless/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ describe("with-remix-headless", () => {
});

describe("login", () => {
it.skip("should login", () => {
it("should login", () => {
login();
cy.location("pathname").should("eq", "/posts");
cy.getAllCookies().then((cookies) => {
expect(cookies[0]).to.have.property("name", "user");
});
});

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");

Expand All @@ -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();
Expand All @@ -74,7 +74,7 @@ describe("with-remix-headless", () => {
});

describe("logout", () => {
it.skip("should logout", () => {
it("should logout", () => {
login();
cy.get("button")
.contains(/logout/i)
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/with-remix-vite-headless/all.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ 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) => {
expect(cookies[0]).to.have.property("name", "user");
});
});

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");

Expand All @@ -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();
Expand All @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/hooks/auth/useLogin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export function useLogin<TVariables = {}>({
}
}

await invalidateAuthStore();
setTimeout(() => {
invalidateAuthStore();
}, 32);
},
onError: (error: any) => {
open?.(buildNotification(error));
Expand Down Expand Up @@ -219,7 +221,9 @@ export function useLogin<TVariables = {}>({
}
}

await invalidateAuthStore();
setTimeout(() => {
invalidateAuthStore();
}, 32);

close?.("login-error");
},
Expand Down

0 comments on commit 5ce59d0

Please sign in to comment.