20 lines
598 B
TypeScript
20 lines
598 B
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getSessionCookie } from "better-auth/cookies";
|
|
|
|
export async function middleware(request: NextRequest) {
|
|
const sessionCookie = getSessionCookie(request);
|
|
|
|
// Check cookie presence - prevents obviously unauthorized users
|
|
if (!sessionCookie) {
|
|
return NextResponse.redirect(new URL('/sign-in', request.url));
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: [
|
|
'/((?!api|_next/static|_next/image|favicon.ico|sign-in|sign-up|forgot-password|reset-password|assets).*)',
|
|
],
|
|
};
|