Skip to content

Commit

Permalink
Merge pull request #103 from gfa-cc-after/fix/protected-pages
Browse files Browse the repository at this point in the history
refactor: protectedpage on frontend
  • Loading branch information
markkovari authored Sep 7, 2024
2 parents bc24bc6 + b5f12fe commit cdfebd1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions frontend/src/pages/utils/ProtectedPage.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { PropsWithChildren } from "react";
import { Navigate } from "react-router-dom";
import { usePetClinicState } from "../../state";
import { Login } from "../Login";

type ProtectedPageProps = PropsWithChildren;

const ProtectedPage = ({ children }: ProtectedPageProps) => {
const {
auth: { user },
} = usePetClinicState();
if (user) {
return <>{children}</>;
if (!user) {
return <Navigate to="/login" />;
}
return <Login />;
return <>{children}</>;
};
export { ProtectedPage };

0 comments on commit cdfebd1

Please sign in to comment.