mirror of
https://github.com/ZSCGR/CloudFlare-ImgBed.git
synced 2026-08-17 22:23:42 +08:00
- 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
30 lines
812 B
JavaScript
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,
|
|
});
|
|
}
|