Skip to content

Commit

Permalink
Merge branch 'login-redirect' of 'https://github.com/evamillan/grimoi…
Browse files Browse the repository at this point in the history
  • Loading branch information
jjmerchante authored Sep 13, 2024
2 parents 57f5acf + 30bdb65 commit d07cc1e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Redirect to the original URL after log in
category: added
author: Eva Millán <evamillan@bitergia.com>
issue: 925
notes: >
Users are now redirected to the page they originally
requested after they log in.
3 changes: 3 additions & 0 deletions ui/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ router.beforeEach((to, from, next) => {
if (!isAuthenticated) {
next({
path: "/login",
query: {
redirect: to.fullPath,
},
});
} else {
next();
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
};
const response = await this.login(authDetails);
if (response) {
this.$router.push("/");
this.$router.push(this.$route.query.redirect || "/");
this.$logger.info(`Log in user ${this.username}`);
}
} catch (error) {
Expand Down
17 changes: 17 additions & 0 deletions ui/tests/e2e/specs/spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ describe("Login", () => {
cy.location("pathname").should("equal", "/login");
cy.contains("Invalid credentials").should("be.visible");
});

it("Redirects to the original URL after login", () => {
const path = "/settings/general";

cy.visit(path);
cy.location("pathname").should("equal", "/login");

cy.get("[id=username]").type(Cypress.env("USERNAME"));
cy.get("[id=password]").type(Cypress.env("PASSWORD"));
cy.contains("button", "Log in").click();
cy.wait("@auth")
.its("response.body.user")
.should("equal", Cypress.env("USERNAME"));

// Redirects to the original path
cy.location("pathname").should("equal", path);
});
});

describe("Authenticated operations", () => {
Expand Down

0 comments on commit d07cc1e

Please sign in to comment.