All checks were successful
Docker Build and Push / build-and-push (push) Successful in 15m8s
15 lines
591 B
TypeScript
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
|
|
}; |