feat: add auth
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 15m8s
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 15m8s
This commit is contained in:
15
middleware.ts
Normal file
15
middleware.ts
Normal file
@ -0,0 +1,15 @@
|
||||
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
|
||||
};
|
||||
Reference in New Issue
Block a user