mirror of
https://github.com/Mail-0/Zero.git
synced 2026-06-29 15:26:42 +00:00
24 lines
657 B
TypeScript
24 lines
657 B
TypeScript
import type { NextRequest } from "next/server";
|
|
import { NextResponse } from "next/server";
|
|
import { auth } from "@/lib/auth";
|
|
|
|
export async function middleware(request: NextRequest) {
|
|
const session = await auth.api.getSession({ headers: request.headers });
|
|
|
|
// Protect /mail routes
|
|
if (request.nextUrl.pathname.startsWith("/mail")) {
|
|
if (!session) {
|
|
// Redirect to login if not authenticated
|
|
const loginUrl = new URL("/login", request.url);
|
|
return NextResponse.redirect(loginUrl);
|
|
}
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
// Configure which routes to run middleware on
|
|
export const config = {
|
|
matcher: ["/mail/:path*"],
|
|
};
|