2021-02-03 07:59:00 +00:00
|
|
|
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";
|
2021-10-21 05:36:17 +00:00
|
|
|
import { APPLICATIONS_URL, AUTH_LOGIN_URL } from "constants/routes";
|
2021-02-03 07:59:00 +00:00
|
|
|
|
2021-10-21 05:36:17 +00:00
|
|
|
export const requiresUnauth = (Component: React.ComponentType) => {
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2021-04-28 10:28:39 +00:00
|
|
|
function Wrapped(props: any) {
|
2021-02-03 07:59:00 +00:00
|
|
|
const user = useSelector(getCurrentUser);
|
2022-04-07 17:57:32 +00:00
|
|
|
if (!user) return null;
|
2021-02-03 07:59:00 +00:00
|
|
|
if (user?.email && user?.email !== ANONYMOUS_USERNAME) {
|
|
|
|
|
return <Redirect to={APPLICATIONS_URL} />;
|
|
|
|
|
}
|
|
|
|
|
return <Component {...props} />;
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2021-02-03 07:59:00 +00:00
|
|
|
|
|
|
|
|
return Wrapped;
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-21 05:36:17 +00:00
|
|
|
export const requiresAuth = (Component: React.ComponentType) => {
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2021-10-21 05:36:17 +00:00
|
|
|
return function Wrapped(props: any) {
|
|
|
|
|
const user = useSelector(getCurrentUser);
|
2022-04-07 17:57:32 +00:00
|
|
|
if (!user) return null;
|
2021-10-21 05:36:17 +00:00
|
|
|
if (user?.email && user?.email !== ANONYMOUS_USERNAME) {
|
|
|
|
|
return <Component {...props} />;
|
|
|
|
|
}
|
|
|
|
|
return <Redirect to={AUTH_LOGIN_URL} />;
|
|
|
|
|
};
|
|
|
|
|
};
|