Skip to content

Commit

Permalink
Merge pull request #90 from CapgeminiInventUK/feat/enable-auth-flag
Browse files Browse the repository at this point in the history
fix(#71): correct full docker compose to use .env.docker
  • Loading branch information
georgeherby authored Mar 10, 2024
2 parents cf12259 + 979d4e2 commit 1962c49
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/ui/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { authOptions } from '@/lib/utils/auth-options';
import NextAuth from 'next-auth';

const handler = NextAuth(authOptions);
const handler = NextAuth( authOptions);
export { handler as GET, handler as POST };
2 changes: 1 addition & 1 deletion packages/ui/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <>
<div className="flex gap-4">
<div className="w-2/3">
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/components/global/app-bar/app-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default async function AppBar() {
<Breadcrumbs/>
<div className="ml-auto flex items-end space-x-2">
<ThemeToggle/>
{session &&
{(session && process.env.NEXTAUTH_ENABLE === 'true')
&&
<SignOutIconButton/>
}
</div>
Expand Down
11 changes: 5 additions & 6 deletions packages/ui/src/components/global/app-bar/breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@ export default function Breadcrumbs() {
<Breadcrumb>
<BreadcrumbList>
{breadcrumbMap.map((item, index) => <>
{ index > 0 &&
<BreadcrumbSeparator/>}
<BreadcrumbItem key={index}>
{index > 0 &&
<BreadcrumbSeparator key={index+'-separator'}/>}
<BreadcrumbItem key={index+'-item'}>
{item.href ? (
<BreadcrumbLink href={item.href}>
<BreadcrumbLink key={index+'-link'} href={item.href}>
{item.label}
</BreadcrumbLink>
) : (
<BreadcrumbPage>{item.label}</BreadcrumbPage>
<BreadcrumbPage key={index+'-page'}>{item.label}</BreadcrumbPage>
)}
</BreadcrumbItem>

</>)}
</BreadcrumbList>
</Breadcrumb>
Expand Down
19 changes: 17 additions & 2 deletions packages/ui/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
export { default } from 'next-auth/middleware';
import { NextRequestWithAuth, withAuth } from 'next-auth/middleware';
import { NextResponse } from 'next/server';

export default function middleware(req: NextRequestWithAuth) {
const isAuthEnabled = process.env.NEXTAUTH_ENABLE === 'true' ;

if (isAuthEnabled) {
return (withAuth(req));
} else {
console.warn('Auth is disabled');
return NextResponse.next();
}
}



export const config = {
matcher: ['/:path*'],
matcher: [ '/:path*' ],
};

0 comments on commit 1962c49

Please sign in to comment.