From 1c849eac77f8c794842e9858ea97f1e5c24c82bc Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Fri, 17 Nov 2023 17:22:43 +0700 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Require=20auth=20for=20sel?= =?UTF-8?q?f=20hosters=20with=20app=20router=20(#938)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/src/app/[locale]/(admin)/layout.tsx | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apps/web/src/app/[locale]/(admin)/layout.tsx b/apps/web/src/app/[locale]/(admin)/layout.tsx index dbe60c4ce..5f7fa20fb 100644 --- a/apps/web/src/app/[locale]/(admin)/layout.tsx +++ b/apps/web/src/app/[locale]/(admin)/layout.tsx @@ -1,6 +1,34 @@ "use client"; +import { signIn, useSession } from "next-auth/react"; +import React from "react"; + import { StandardLayout } from "@/components/layouts/standard-layout"; +import { isSelfHosted } from "@/utils/constants"; + +const Auth = ({ children }: { children: React.ReactNode }) => { + const session = useSession(); + const isAuthenticated = !!session.data?.user.email; + + React.useEffect(() => { + if (!isAuthenticated) { + signIn(); + } + }, [isAuthenticated]); + + if (isAuthenticated) { + return <>{children}; + } + + return null; +}; export default function Layout({ children }: { children: React.ReactNode }) { + if (isSelfHosted) { + return ( + + {children} + + ); + } return {children}; }