Skip to content

Commit

Permalink
fix: 评论无法回复
Browse files Browse the repository at this point in the history
  • Loading branch information
wsvaio committed Apr 28, 2024
1 parent 2e4fb2e commit f3b01d8
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions server/middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import jwt from "jsonwebtoken";

export default defineEventHandler(async event => {
if (
(!["get", "options"].includes(event.method.toLowerCase()) && !event.path.startsWith("/api/admin/login")) && !event.path.startsWith("/api/file") && !(/\/api\/article\/\d+\/comment/.test(event.path))
|| event.path.startsWith("/api/admin/info")
if (["get", "options"].includes(event.method.toLowerCase()))
return;
if (event.path.startsWith("/api/admin/login"))
return;
if (event.path.startsWith("/api/file"))
return;
if (/\/api\/article\/\d+\/comment/.test(event.path))
return;
if (/\/api\/comment\/\d+\/comment/.test(event.path))
return;
if (event.path.startsWith("/api/admin/info"))
return;

) {
const authorization = getHeader(event, "Authorization") || "";
const authorization = getHeader(event, "Authorization") || "";

// if (!authorization) return new Error("Authorization不存在");
// if (!authorization) return new Error("Authorization不存在");

try {
// 偷懒暂时先拿 EMAIL_PASS 做secretOrPublicKey
const admin = jwt.verify(authorization, import.meta.env.EMAIL_PASS);
event.context.admin = admin;
}
catch (err) {
throw new Error("无可奈何");
}
try {
// 偷懒暂时先拿 EMAIL_PASS 做secretOrPublicKey
const admin = jwt.verify(authorization, import.meta.env.EMAIL_PASS);
event.context.admin = admin;
}
catch (err) {
throw new Error("无可奈何");
}
});

0 comments on commit f3b01d8

Please sign in to comment.