initial admin
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { getSessionCookie } from "better-auth/cookies";
|
||||
import { type NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function proxy(request: NextRequest) {
|
||||
const sessionCookie = getSessionCookie(request);
|
||||
|
||||
// THIS IS NOT SECURE!
|
||||
// This is the recommended approach to optimistically redirect users
|
||||
// We recommend handling auth checks in each page/route
|
||||
if (!sessionCookie) {
|
||||
const url = new URL("/login", request.url);
|
||||
url.searchParams.set(
|
||||
"next",
|
||||
request.nextUrl.pathname + request.nextUrl.search,
|
||||
);
|
||||
return NextResponse.redirect(url);
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
"/artifact/admin/:path*",
|
||||
"/tl/:path*/:path*/admin",
|
||||
"/admin/:path*",
|
||||
], // Specify the routes the middleware applies to
|
||||
};
|
||||
Reference in New Issue
Block a user