Skip to content

Commit

Permalink
Merge pull request #14 from josephdburdick/fix/redirect-unauthorized-…
Browse files Browse the repository at this point in the history
…private-route

Redirect unauthorized reqests within PrivateRoute. Closes #12
  • Loading branch information
Jaaneek authored Jan 22, 2024
2 parents 97e8219 + 690ad71 commit 18d6b0a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/PrivateRoute/PrivateRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { type PropsWithChildren } from "react";
import { getServerUser } from "~/utils/auth";
import { PrivateRouteBase } from "./PrivateRouteBase";
import { redirect } from "next/navigation";

export const PrivateRoute = async ({ children }: PropsWithChildren) => {
const user = await getServerUser();

if (!user) return null; // Prevent server side render of authorized page
if (!user) redirect("/login");

return <PrivateRouteBase>{children}</PrivateRouteBase>;
};

0 comments on commit 18d6b0a

Please sign in to comment.