81965595f0
Co-authored-by: Copilot <copilot@github.com>
22 lines
652 B
TypeScript
22 lines
652 B
TypeScript
import type { IUserLogoutData } from "#shared/types";
|
|
import {
|
|
clearNewApiAuthCookies,
|
|
createSuccessResponse,
|
|
newApiAuthedFetch
|
|
} from "~~/server/utils";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
// 带上本站 httpOnly cookie 中的 NewAPI 登录态,请求上游销毁 session。
|
|
await newApiAuthedFetch<IUserLogoutData>(event, "/api/user/logout", {
|
|
method: "GET"
|
|
});
|
|
} catch {
|
|
// 上游 session 可能已失效,本地仍然必须清理,避免残留坏登录态。
|
|
} finally {
|
|
clearNewApiAuthCookies(event);
|
|
}
|
|
|
|
return createSuccessResponse<IUserLogoutData>(null, "登出成功");
|
|
});
|