Skip to content

Commit 7e2400d

Browse files
mrjasonroyclaude
andcommitted
fix: restore missing middleware file from main
The middleware.ts file was missing from cn/main branch, causing /admin to return 404 instead of redirecting to /admin/users. This restores the middleware from main branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent a0f1de7 commit 7e2400d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/middleware.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { NextResponse, type NextRequest } from "next/server";
2+
import { getSessionCookie } from "better-auth/cookies";
3+
4+
export async function middleware(request: NextRequest) {
5+
const { pathname } = request.nextUrl;
6+
7+
/*
8+
* Playwright starts the dev server and requires a 200 status to
9+
* begin the tests, so this ensures that the tests can start
10+
*/
11+
if (pathname.startsWith("/ping")) {
12+
return new Response("pong", { status: 200 });
13+
}
14+
15+
if (pathname === "/admin") {
16+
return NextResponse.redirect(new URL("/admin/users", request.url));
17+
}
18+
19+
const sessionCookie = getSessionCookie(request);
20+
21+
if (!sessionCookie) {
22+
return NextResponse.redirect(new URL("/sign-in", request.url));
23+
}
24+
return NextResponse.next();
25+
}
26+
27+
export const config = {
28+
matcher: [
29+
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|api/auth|export|sign-in|sign-up).*)",
30+
],
31+
};

0 commit comments

Comments
 (0)