diff --git a/web/src/app/admin/layout.tsx b/web/src/app/admin/layout.tsx index f92e280b6..3c52a919e 100644 --- a/web/src/app/admin/layout.tsx +++ b/web/src/app/admin/layout.tsx @@ -7,6 +7,7 @@ import { GoogleDriveIcon, SlackIcon, } from "@/components/icons/icons"; +import { DISABLE_AUTH } from "@/lib/constants"; import { getCurrentUserSS } from "@/lib/userSS"; import { redirect } from "next/navigation"; @@ -15,12 +16,15 @@ export default async function AdminLayout({ }: { children: React.ReactNode; }) { - const user = await getCurrentUserSS(); - if (!user) { - return redirect("/auth/login"); - } - if (user.role !== "admin") { - return redirect("/"); + let user = null; + if (!DISABLE_AUTH) { + user = await getCurrentUserSS(); + if (!user) { + return redirect("/auth/login"); + } + if (user.role !== "admin") { + return redirect("/"); + } } return ( diff --git a/web/src/app/auth/login/page.tsx b/web/src/app/auth/login/page.tsx index a9761cfc9..8fc573742 100644 --- a/web/src/app/auth/login/page.tsx +++ b/web/src/app/auth/login/page.tsx @@ -1,7 +1,13 @@ +import { DISABLE_AUTH } from "@/lib/constants"; import { getGoogleOAuthUrlSS, getCurrentUserSS } from "@/lib/userSS"; import { redirect } from "next/navigation"; const Page = async () => { + // no need for any of the below if auth is disabled + if (DISABLE_AUTH) { + return redirect("/"); + } + const [currentUser, authorizationUrl] = await Promise.all([ getCurrentUserSS(), getGoogleOAuthUrlSS(), diff --git a/web/src/app/layout.tsx b/web/src/app/layout.tsx index 637610697..a8363e680 100644 --- a/web/src/app/layout.tsx +++ b/web/src/app/layout.tsx @@ -1,9 +1,6 @@ -import { Header } from "@/components/Header"; import "./globals.css"; import { Inter } from "next/font/google"; -import { getCurrentUserSS } from "@/lib/userSS"; -import { redirect } from "next/navigation"; const inter = Inter({ subsets: ["latin"], diff --git a/web/src/app/page.tsx b/web/src/app/page.tsx index 568ceff06..c396a3a22 100644 --- a/web/src/app/page.tsx +++ b/web/src/app/page.tsx @@ -2,11 +2,15 @@ import { SearchSection } from "@/components/search/SearchSection"; import { Header } from "@/components/Header"; import { getCurrentUserSS } from "@/lib/userSS"; import { redirect } from "next/navigation"; +import { DISABLE_AUTH } from "@/lib/constants"; export default async function Home() { - const user = await getCurrentUserSS(); - if (!user) { - return redirect("/auth/login"); + let user = null; + if (!DISABLE_AUTH) { + user = await getCurrentUserSS(); + if (!user && !DISABLE_AUTH) { + return redirect("/auth/login"); + } } return ( <> diff --git a/web/src/components/Header.tsx b/web/src/components/Header.tsx index 5241b5147..6820e44b2 100644 --- a/web/src/components/Header.tsx +++ b/web/src/components/Header.tsx @@ -9,7 +9,7 @@ import { useRouter } from "next/navigation"; import React, { useEffect, useRef, useState } from "react"; interface HeaderProps { - user: User; + user: User | null; } export const Header: React.FC = ({ user }) => { @@ -74,19 +74,21 @@ export const Header: React.FC = ({ user }) => { "w-36 overflow-hidden shadow-xl z-10 text-sm text-gray-300" } > - {user.role === "admin" && ( + {user?.role === "admin" && (
Connectors
)} -
- Logout -
+ {user && ( +
+ Logout +
+ )} )} diff --git a/web/src/lib/constants.ts b/web/src/lib/constants.ts new file mode 100644 index 000000000..2b64832e3 --- /dev/null +++ b/web/src/lib/constants.ts @@ -0,0 +1 @@ +export const DISABLE_AUTH = process.env.DISABLE_AUTH?.toLowerCase() === "true";