N-FIN-93: migrate to middleware route handling
This commit is contained in:
parent
4720ff553d
commit
e38157e604
4 changed files with 30 additions and 8 deletions
|
@ -1,3 +0,0 @@
|
|||
import { handleAuth } from '@auth0/nextjs-auth0';
|
||||
|
||||
export const GET = handleAuth();
|
|
@ -5,7 +5,6 @@ import { cn } from '@/lib/utils';
|
|||
import { Toaster } from '@/components/ui/sonner';
|
||||
import React from 'react';
|
||||
import Navigation from '@/components/navigation';
|
||||
import { UserProvider } from '@auth0/nextjs-auth0/client';
|
||||
|
||||
const inter = Inter({subsets: ['latin']});
|
||||
|
||||
|
@ -50,7 +49,6 @@ export default function RootLayout({
|
|||
href="/logo_white.png"
|
||||
/>
|
||||
</head>
|
||||
<UserProvider>
|
||||
<body className={cn('dark', inter.className)}>
|
||||
<Navigation/>
|
||||
<main className="p-4 sm:p-8">
|
||||
|
@ -58,7 +56,6 @@ export default function RootLayout({
|
|||
</main>
|
||||
<Toaster/>
|
||||
</body>
|
||||
</UserProvider>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
|
9
src/lib/auth.ts
Normal file
9
src/lib/auth.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { Auth0Client } from "@auth0/nextjs-auth0/server"
|
||||
|
||||
export const auth0 = new Auth0Client({
|
||||
appBaseUrl: process.env.AUTH0_BASE_URL,
|
||||
domain: process.env.AUTH0_ISSUER_BASE_URL,
|
||||
secret: process.env.AUTH0_SECRET,
|
||||
clientId: process.env.AUTH0_CLIENT_ID,
|
||||
clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
||||
})
|
|
@ -1,3 +1,22 @@
|
|||
import { withMiddlewareAuthRequired } from '@auth0/nextjs-auth0/edge';
|
||||
import { NextRequest } from 'next/server';
|
||||
import { auth0 } from '@/lib/auth';
|
||||
|
||||
export default withMiddlewareAuthRequired();
|
||||
export async function middleware(request: NextRequest) {
|
||||
try {
|
||||
return await auth0.middleware(request);
|
||||
} catch (error) {
|
||||
console.error("Auth0 middleware error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
/*
|
||||
* Match all request paths except for the ones starting with:
|
||||
* - _next/static (static files)
|
||||
* - _next/image (image optimization files)
|
||||
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
|
||||
*/
|
||||
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
|
||||
],
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue