diff --git a/examples/with-shadcn/app/page.tsx b/examples/with-shadcn/app/page.tsx index caa888963..88191a229 100644 --- a/examples/with-shadcn/app/page.tsx +++ b/examples/with-shadcn/app/page.tsx @@ -13,6 +13,7 @@ import { SidebarProvider, SidebarTrigger, } from "@/components/ui/sidebar" +import Link from "next/link" export default function Page() { return ( @@ -40,7 +41,11 @@ export default function Page() {
-
+
+ Go to Test + Go to Test2 + Go to Test3 +
diff --git a/examples/with-shadcn/app/test/page.tsx b/examples/with-shadcn/app/test/page.tsx new file mode 100644 index 000000000..07f1f6b14 --- /dev/null +++ b/examples/with-shadcn/app/test/page.tsx @@ -0,0 +1,5 @@ +export default function Page() { + return ( +
Protected Page 1
+ ); +} diff --git a/examples/with-shadcn/app/test2/page.tsx b/examples/with-shadcn/app/test2/page.tsx new file mode 100644 index 000000000..83cd49be2 --- /dev/null +++ b/examples/with-shadcn/app/test2/page.tsx @@ -0,0 +1,5 @@ +export default function Page() { + return ( +
Protected Page 2
+ ); +} diff --git a/examples/with-shadcn/app/test3/page.tsx b/examples/with-shadcn/app/test3/page.tsx new file mode 100644 index 000000000..78221417a --- /dev/null +++ b/examples/with-shadcn/app/test3/page.tsx @@ -0,0 +1,5 @@ +export default function Page() { + return ( +
Protected Page 3
+ ); +} diff --git a/examples/with-shadcn/middleware.ts b/examples/with-shadcn/middleware.ts index a2a202538..267d67c54 100644 --- a/examples/with-shadcn/middleware.ts +++ b/examples/with-shadcn/middleware.ts @@ -1,8 +1,19 @@ -import type { NextRequest } from "next/server" +import { NextResponse, type NextRequest } from "next/server"; -import { auth0 } from "./lib/auth0" +import { auth0 } from "./lib/auth0"; export async function middleware(request: NextRequest) { + // Protecting all routes that start with /test + if (request.nextUrl.pathname.startsWith("/test")) { + const session = await auth0.getSession(request); + + if (!session) { + // user is not authenticated, redirect to login page + return NextResponse.redirect( + new URL("/auth/login", request.nextUrl.origin) + ); + } + } return await auth0.middleware(request); }