feat:移除了弹窗,服务器添加sls

This commit is contained in:
2026-09-08 22:39:45 +08:00
commit 6a295f9a7a
4082 changed files with 1322534 additions and 0 deletions

View File

@ -0,0 +1,36 @@
import { getHeader } from 'h3'
import { toAdminHttpError } from '../utils/admin-http-error'
import {
accessSettings,
authenticateAccessToken,
mockAuthEnabled,
mockScenario,
mockSession,
} from '../utils/auth'
import { AdminApiError, unauthorized, unavailable } from '../utils/errors'
import type { AdminEventContext } from '../utils/service'
export default defineEventHandler(async (event) => {
if (!event.path.startsWith('/api/admin/')) return
try {
const config = useRuntimeConfig(event)
if (mockAuthEnabled(config)) {
;(event.context as AdminEventContext).adminSession = mockSession(mockScenario(config))
return
}
const settings = accessSettings(config)
if (!settings) {
if (process.env.NODE_ENV === 'production') throw unavailable()
throw unauthorized()
}
const token = getHeader(event, 'cf-access-jwt-assertion')
;(event.context as AdminEventContext).adminSession = await authenticateAccessToken(
token,
settings,
)
} catch (error) {
if (error instanceof AdminApiError) throw toAdminHttpError(error)
throw error
}
})