Files
CloudFlare-ImgBed/functions/api/auth/logout.js
T
MarSeventh 4d2796f54a refactor: unify auth logic into authCore with authScope parameter
- Extract shared authentication logic into utils/auth/authCore.js
- Replace enableBasicAuth/enableAuthCode flags with clear authScope enum (ADMIN/USER/EITHER)
- Move all auth-related files into utils/auth/ subdirectory
- Eliminate duplicated admin auth logic between _middleware.js and dualAuth.js
- Fix: user session no longer grants access to admin-only endpoints
- Fix: dualAuth no longer bypasses authCode when admin is not configured
- Update all 17 import references across the codebase
- Preserve original function signatures (userAuthCheck, dualAuthCheck) for zero caller changes
2026-04-18 13:24:53 +08:00

30 lines
812 B
JavaScript

import { destroySession } from "../../utils/auth/sessionManager.js";
export async function onRequestPost(context) {
const { request, env } = context;
// 从请求体中获取要登出的类型,默认清除所有
let authType = null;
try {
const body = await request.json();
authType = body.authType || null;
} catch {
// 没有请求体,清除所有
}
const result = await destroySession(env, request, authType);
// result 可能是单个字符串或数组
const headers = new Headers();
if (Array.isArray(result)) {
result.forEach(cookie => headers.append('Set-Cookie', cookie));
} else {
headers.set('Set-Cookie', result);
}
return new Response('Logged out', {
status: 200,
headers,
});
}