Files
evanpage/frontend/middleware.ts
evan 37cecaa1ce frontend: add bookmark management and homepage navigation
Admin-only /bookmarks page for managing entries; homepage now renders
public bookmarks as a category-grouped navigation grid (empty state
links admin to the manager). Dashboard gains a recent-bookmarks card,
dock and main layout get a bookmark entry for admins, and the
middleware protects /bookmarks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-03 01:51:55 +08:00

35 lines
1.1 KiB
TypeScript

import { auth } from "@/auth";
import { NextResponse } from "next/server";
export default auth((req) => {
const { nextUrl } = req;
const isLoggedIn = !!req.auth;
const role = (req.auth?.user as any)?.role || "guest";
const isAuthPage = nextUrl.pathname.startsWith("/login") ||
nextUrl.pathname.startsWith("/register") ||
nextUrl.pathname.startsWith("/bind-account");
const isProtected = nextUrl.pathname.startsWith("/dashboard") ||
nextUrl.pathname.startsWith("/bookmarks") ||
nextUrl.pathname.startsWith("/admin");
if (isLoggedIn && isAuthPage) {
return NextResponse.redirect(new URL("/dashboard", nextUrl));
}
if (!isLoggedIn && isProtected) {
return NextResponse.redirect(new URL("/login", nextUrl));
}
if (nextUrl.pathname.startsWith("/admin") && role !== "admin") {
return NextResponse.redirect(new URL("/unauthorized", nextUrl));
}
return NextResponse.next();
});
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};