Dev #25

Merged
zhangxiang merged 46 commits from dev into main 2026-09-01 14:55:21 +08:00
Showing only changes of commit 2297f01e60 - Show all commits
+4 -3
View File
@@ -8,7 +8,8 @@ interface JwtPayload {
}
// ============ Edge-compatible JWT 验证 ============
// Next.js Middleware 运行在 Edge Runtime不能依赖 jsonwebtoken 的 Node crypto。
// Next.js Proxy(原 Middleware 约定,Next 16 起重命名)运行在 Edge Runtime
// 不能依赖 jsonwebtoken 的 Node crypto。
// 这里使用 Web Crypto API 实现 HS256 签名验证,与 API 路由中的 jsonwebtoken 共享同一密钥。
function base64urlToBuffer(value: string): Uint8Array {
@@ -65,7 +66,7 @@ async function verifyAccessTokenEdge(token: string): Promise<JwtPayload> {
return payload;
}
// ============ Middleware ============
// ============ Proxy(原 MiddlewareNext 16 弃用 middleware 约定) ============
function redirectToLogin(request: NextRequest, pathname: string): NextResponse {
const loginUrl = new URL('/admin/login', request.url);
@@ -73,7 +74,7 @@ function redirectToLogin(request: NextRequest, pathname: string): NextResponse {
return NextResponse.redirect(loginUrl);
}
export async function middleware(request: NextRequest) {
export async function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
// 只处理 /admin 路由(除了登录页和 API 路由)