feat: 完成登录session处理

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-24 22:22:21 +08:00
parent 5294528148
commit 81965595f0
15 changed files with 804 additions and 240 deletions
+11 -12
View File
@@ -1,22 +1,21 @@
// server/api/auth/logout.get.ts
import type { IUserLogoutData } from "#shared/types";
import {
clearNewApiAuthCookies,
createSuccessResponse,
createUpstreamErrorResponse,
newApiFetch
newApiAuthedFetch
} from "~~/server/utils";
/**
* GET /api/auth/logout
*/
export default defineEventHandler(async () => {
export default defineEventHandler(async (event) => {
try {
await newApiFetch<IUserLogoutData>("/api/user/logout", {
// 带上本站 httpOnly cookie 中的 NewAPI 登录态,请求上游销毁 session。
await newApiAuthedFetch<IUserLogoutData>(event, "/api/user/logout", {
method: "GET"
});
return createSuccessResponse<IUserLogoutData>(null, "登出成功");
} catch (error) {
return createUpstreamErrorResponse(error, "登出失败");
} catch {
// 上游 session 可能已失效,本地仍然必须清理,避免残留坏登录态。
} finally {
clearNewApiAuthCookies(event);
}
return createSuccessResponse<IUserLogoutData>(null, "登出成功");
});