Files
tunnl_please_frontend/middleware.ts
bagas 018a980dcb
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 15m8s
feat: add auth
2025-10-01 17:16:58 +07:00

15 lines
591 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { getSessionCookie } from "better-auth/cookies";
export async function middleware(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) {
return NextResponse.redirect(new URL("/", request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/login"], // Specify the routes the middleware applies to
};