Skip to content

Commit

Permalink
suppress prop-spearding warning for loginpage
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Einars <[email protected]>
  • Loading branch information
polaroidkidd committed Jul 17, 2022
1 parent ba31002 commit 75e51c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
37 changes: 2 additions & 35 deletions src/layouts/PrivateRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
import React, { FC } from "react";
import { Navigate, Outlet, useLocation } from "react-router-dom";
import React from "react";
import { Navigate, Outlet } from "react-router-dom";

import { selectIsAuthenticated } from "../store/auth/authSelectors";
import { useAppSelector } from "../store/store";

// Router and Switch are needed Breaks site if not in import. DW

// export function PrivateRoute({ component: Component, path, ...rest }) {
// const isAuthenticated = useAppSelector(state => !isRefreshTokenExpired(state));
// return (
// <Route
// {...rest}
// render={props =>
// isAuthenticated ? (
// <Component {...props} />
// ) : (
// <Redirect
// to={{
// pathname: "/login",
// state: { from: props.location },
// }}
// />
// )
// }
// />
// );
// }

interface IProtectedRoute {
children: JSX.Element[];
}

export function ProtectedRoute() {
const isAuth = useAppSelector(selectIsAuthenticated);
const location = useLocation();

if (!isAuth) {
console.info(Date.now(), "ProtectedRoute.isAuth: ", isAuth);
// Redirect them to the /login page, but save the current location they were
// trying to go to when they were redirected. This allows us to send them
// along to that page after they login, which is a nicer user experience
// than dropping them off on the home page.
return <Navigate to="/login" replace />;
}

Expand Down
5 changes: 3 additions & 2 deletions src/layouts/login/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useForm } from "@mantine/form";
import type { FormEvent } from "react";
import React, { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { Navigate, useLocation, useNavigate } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import { Lock, User } from "tabler-icons-react";

import { fetchSiteSettings } from "../../actions/utilActions";
Expand All @@ -29,7 +29,6 @@ export function LoginPage(): JSX.Element {
const isAuth = useAppSelector(selectIsAuthenticated);
const { colorScheme } = useMantineColorScheme();
const dark = colorScheme === "dark";
const location = useLocation();
const dispatch = useAppDispatch();
const { t } = useTranslation();

Expand Down Expand Up @@ -93,13 +92,15 @@ export function LoginPage(): JSX.Element {
icon={<User />}
placeholder={t("login.usernameplaceholder")}
name="username"
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...form.getInputProps("username")}
/>
<PasswordInput
required
icon={<Lock />}
placeholder={t("login.passwordplaceholder")}
name="password"
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...form.getInputProps("password")}
/>
<Button variant="gradient" gradient={{ from: "#43cea2", to: "#185a9d" }} type="submit">
Expand Down

0 comments on commit 75e51c8

Please sign in to comment.