From 77c6868cd88b1120c140c15f55b3d210c26b987c Mon Sep 17 00:00:00 2001 From: George Herbert Date: Sun, 10 Mar 2024 15:40:48 +0000 Subject: [PATCH] fix(#71): correct full docker compose to use .env.docker --- packages/ui/.env.example | 2 +- packages/ui/src/app/api/auth/[...nextauth]/route.ts | 9 ++++++++- packages/ui/src/app/page.tsx | 2 +- packages/ui/src/components/global/app-bar/app-bar.tsx | 3 ++- .../ui/src/components/global/app-bar/breadcrumbs.tsx | 11 +++++------ packages/ui/src/middleware.ts | 11 +++++++++++ 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/packages/ui/.env.example b/packages/ui/.env.example index 004c5c34..d43b8bdc 100644 --- a/packages/ui/.env.example +++ b/packages/ui/.env.example @@ -3,7 +3,7 @@ LANGTRACE_API_URL=http://localhost:1984 # Auth NEXTAUTH_ENABLE=false -NEXTAUTH_URL=http://localhost:3000 +#NEXTAUTH_URL=http://localhost:3000 #NEXTAUTH_SECRET= ## Github diff --git a/packages/ui/src/app/api/auth/[...nextauth]/route.ts b/packages/ui/src/app/api/auth/[...nextauth]/route.ts index 3ea5f262..edb19b5d 100644 --- a/packages/ui/src/app/api/auth/[...nextauth]/route.ts +++ b/packages/ui/src/app/api/auth/[...nextauth]/route.ts @@ -1,5 +1,12 @@ import { authOptions } from '@/lib/utils/auth-options'; import NextAuth from 'next-auth'; +import { NextApiRequest, NextApiResponse } from 'next'; -const handler = NextAuth(authOptions); +const handler = (req: NextApiRequest, res: NextApiResponse) => { + if (process.env.NEXTAUTH_ENABLE === 'false') { + console.warn('NextAuth is disabled'); + return res.status(200).json({ message: 'NextAuth is disabled' }); + } + return NextAuth(req, res, authOptions); +}; export { handler as GET, handler as POST }; diff --git a/packages/ui/src/app/page.tsx b/packages/ui/src/app/page.tsx index 9df2b5db..1849dc7e 100644 --- a/packages/ui/src/app/page.tsx +++ b/packages/ui/src/app/page.tsx @@ -28,7 +28,7 @@ export const metadata = { export default async function Home() { const session = await getServerSession(authOptions); - if (session) { + if (session || process.env.NEXTAUTH_ENABLE !== 'true') { return <>
diff --git a/packages/ui/src/components/global/app-bar/app-bar.tsx b/packages/ui/src/components/global/app-bar/app-bar.tsx index 3dce3be6..88d1a0c8 100644 --- a/packages/ui/src/components/global/app-bar/app-bar.tsx +++ b/packages/ui/src/components/global/app-bar/app-bar.tsx @@ -15,7 +15,8 @@ export default async function AppBar() {
- {session && + {(session && process.env.NEXTAUTH_ENABLE === 'true') + && }
diff --git a/packages/ui/src/components/global/app-bar/breadcrumbs.tsx b/packages/ui/src/components/global/app-bar/breadcrumbs.tsx index 3cd0d583..b599a76d 100644 --- a/packages/ui/src/components/global/app-bar/breadcrumbs.tsx +++ b/packages/ui/src/components/global/app-bar/breadcrumbs.tsx @@ -46,18 +46,17 @@ export default function Breadcrumbs() { {breadcrumbMap.map((item, index) => <> - { index > 0 && - } - + {index > 0 && + } + {item.href ? ( - + {item.label} ) : ( - {item.label} + {item.label} )} - )} diff --git a/packages/ui/src/middleware.ts b/packages/ui/src/middleware.ts index 8ba99cea..d3de5081 100644 --- a/packages/ui/src/middleware.ts +++ b/packages/ui/src/middleware.ts @@ -1,4 +1,15 @@ +import { NextResponse } from 'next/server'; export { default } from 'next-auth/middleware'; +import type { NextRequest } from 'next/server'; + +export function middleware(request: NextRequest) { + if (process.env.NEXTAUTH_ENABLE === 'false') { + console.warn('NextAuth is disabled middleware'); + return NextResponse.next(); + } + return NextResponse.redirect(new URL(request.url, request.url)); +} + export const config = { matcher: ['/:path*'], };