Implement lists module and dev login setup
This commit is contained in:
+28
-1
@@ -1,4 +1,31 @@
|
||||
export { auth as middleware } from "@/lib/auth";
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
|
||||
const PUBLIC_PREFIXES = ["/api/auth/", "/s/"];
|
||||
const PUBLIC_PATHS = new Set(["/login"]);
|
||||
const SESSION_COOKIE_NAMES = ["authjs.session-token", "__Secure-authjs.session-token"];
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
if (PUBLIC_PATHS.has(pathname) || PUBLIC_PREFIXES.some((prefix) => pathname.startsWith(prefix))) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
if (hasSessionCookie(request)) return NextResponse.next();
|
||||
|
||||
const loginUrl = new URL("/login", request.url);
|
||||
loginUrl.searchParams.set("callbackUrl", request.url);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
|
||||
function hasSessionCookie(request: NextRequest) {
|
||||
return request.cookies
|
||||
.getAll()
|
||||
.some((cookie) =>
|
||||
SESSION_COOKIE_NAMES.some(
|
||||
(name) => cookie.name === name || cookie.name.startsWith(`${name}.`),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
|
||||
Reference in New Issue
Block a user