Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ export async function middleware(request: NextRequest) {
return NextResponse.next();
}

// 其他模式:只验证签名
// 检查是否有用户名(非localStorage模式下密码不存储在cookie中)
if (!authInfo.username || !authInfo.signature) {
if (!authInfo.username || !authInfo.signature || !authInfo.timestamp) {
return handleAuthFailure(request, pathname);
}
if (
typeof authInfo.timestamp !== 'number' ||
authInfo.timestamp > Date.now() + 300000 ||
Date.now() - authInfo.timestamp > 604800000
) {
return handleAuthFailure(request, pathname);
}

// 验证签名(如果存在)
if (authInfo.signature) {
const isValidSignature = await verifySignature(
authInfo.username,
Expand Down