Files
OpenStock/middleware.ts
2026-10-18 06:33:45 +05:30

25 lines
830 B
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { getSessionCookie } from "better-auth/cookies";
const PUBLIC_PATHS = new Set(['/', '/about', '/help', '/terms', '/api-docs', '/sponsor', '/love', '/changelog']);
export async function middleware(request: NextRequest) {
// The marketing site is public
if (PUBLIC_PATHS.has(request.nextUrl.pathname)) return NextResponse.next();
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).*)',
],
};