Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

♻️ Require auth for self hosters with app router (#938)

Luke Vella1c849eac77f8
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 (
+ <Auth>
+ <StandardLayout>{children}</StandardLayout>
+ </Auth>
+ );
+ }
return <StandardLayout>{children}</StandardLayout>;
}