From 271a296f8f04837ba46cf002f02758a12e8b30be Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Fri, 14 Mar 2025 10:14:13 -0700 Subject: [PATCH] fix: redirects /w to /w/1 --- sim/middleware.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 sim/middleware.ts diff --git a/sim/middleware.ts b/sim/middleware.ts new file mode 100644 index 0000000000..cd11e144e6 --- /dev/null +++ b/sim/middleware.ts @@ -0,0 +1,29 @@ +import { NextRequest, NextResponse } from 'next/server' +import { getSessionCookie } from 'better-auth' + +export async function middleware(request: NextRequest) { + // Check if the path is exactly /w + if (request.nextUrl.pathname === '/w') { + return NextResponse.redirect(new URL('/w/1', request.url)) + } + + // Skip auth check if DISABLE_AUTH is set (for standalone mode) + if (process.env.DISABLE_AUTH === 'true' || process.env.NEXT_PUBLIC_DISABLE_AUTH === 'true') { + return NextResponse.next() + } + + // Existing auth check for protected routes + const sessionCookie = getSessionCookie(request) + if (!sessionCookie) { + return NextResponse.redirect(new URL('/login', request.url)) + } + return NextResponse.next() +} + +// TODO: Add protected routes +export const config = { + matcher: [ + '/w', // Match exactly /w + '/w/:path*', // Keep existing matcher for protected routes + ], +} \ No newline at end of file