Fix: redirect to applications page from auth pages when the user is logged in (#2771)
This commit is contained in:
parent
7a9ec45901
commit
8ae86c34e0
|
|
@ -0,0 +1,8 @@
|
|||
describe("Check for redirects associated with auth pages", function() {
|
||||
it("Should redirect away from auth pages if already logged in", function() {
|
||||
const loginPageRoute = "/user/login";
|
||||
cy.visit(loginPageRoute);
|
||||
cy.wait(2000);
|
||||
cy.location("pathname").should("not.equal", loginPageRoute);
|
||||
});
|
||||
});
|
||||
|
|
@ -287,6 +287,11 @@ Cypress.Commands.add("DeleteApp", (appName) => {
|
|||
});
|
||||
|
||||
Cypress.Commands.add("LogintoApp", (uname, pword) => {
|
||||
cy.window()
|
||||
.its("store")
|
||||
.invoke("dispatch", { type: "LOGOUT_USER_INIT" });
|
||||
cy.wait("@postLogout");
|
||||
|
||||
cy.visit("/user/login");
|
||||
cy.get(loginPage.username).should("be.visible");
|
||||
cy.get(loginPage.username).type(uname);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import FooterLinks from "./FooterLinks";
|
|||
import * as Sentry from "@sentry/react";
|
||||
const SentryRoute = Sentry.withSentryRouting(Route);
|
||||
|
||||
import requiresAuthHOC from "./requiresAuthHOC";
|
||||
|
||||
export const UserAuth = () => {
|
||||
const { path } = useRouteMatch();
|
||||
const location = useLocation();
|
||||
|
|
@ -40,4 +42,4 @@ export const UserAuth = () => {
|
|||
);
|
||||
};
|
||||
|
||||
export default UserAuth;
|
||||
export default requiresAuthHOC(UserAuth);
|
||||
|
|
|
|||
22
app/client/src/pages/UserAuth/requiresAuthHOC.tsx
Normal file
22
app/client/src/pages/UserAuth/requiresAuthHOC.tsx
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import React from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { Redirect } from "react-router-dom";
|
||||
|
||||
import { getCurrentUser } from "selectors/usersSelectors";
|
||||
import { ANONYMOUS_USERNAME } from "constants/userConstants";
|
||||
import { APPLICATIONS_URL } from "constants/routes";
|
||||
|
||||
const requiresAuthHOC = (Component: React.ComponentType) => {
|
||||
const Wrapped = (props: any) => {
|
||||
const user = useSelector(getCurrentUser);
|
||||
|
||||
if (user?.email && user?.email !== ANONYMOUS_USERNAME) {
|
||||
return <Redirect to={APPLICATIONS_URL} />;
|
||||
}
|
||||
return <Component {...props} />;
|
||||
};
|
||||
|
||||
return Wrapped;
|
||||
};
|
||||
|
||||
export default requiresAuthHOC;
|
||||
Loading…
Reference in New Issue
Block a user