mirror of
https://github.com/Open-Dev-Society/OpenStock.git
synced 2026-11-24 01:33:16 +08:00
25 lines
830 B
TypeScript
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).*)',
|
|
],
|
|
};
|