From 12e892683ef1189324a9df872875c35ded188ca6 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Fri, 17 Apr 2026 01:16:53 +0800 Subject: [PATCH] refactor: update H3EventContext for authentication and configuration management Replace the existing configuration context type with a new structure that includes an authentication context. The updated context now provides methods for global and user configuration retrieval, enhancing the overall configuration management within the application. The previous config-context.d.ts file has been removed as part of this update. --- server/plugins/01.context.ts | 11 +++++++++++ server/types/config-context.d.ts | 17 ----------------- 2 files changed, 11 insertions(+), 17 deletions(-) delete mode 100644 server/types/config-context.d.ts diff --git a/server/plugins/01.context.ts b/server/plugins/01.context.ts index f15e42c..4075e9f 100644 --- a/server/plugins/01.context.ts +++ b/server/plugins/01.context.ts @@ -7,6 +7,17 @@ if (import.meta.dev) { console.log("plugin: 01.context"); } +declare module "h3" { + interface H3EventContext { + auth: ReturnType; + config: { + getGlobal: (key: K) => Promise>; + getUser: (key: K) => Promise | undefined>; + get: (key: K) => Promise>; + }; + } +} + export default defineNitroPlugin((nitroApp) => { nitroApp.hooks.hook("request", (event) => { const requestCache = new Map>(); diff --git a/server/types/config-context.d.ts b/server/types/config-context.d.ts deleted file mode 100644 index d929eb8..0000000 --- a/server/types/config-context.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { KnownConfigKey, KnownConfigValue } from "../service/config/registry"; - -declare module "h3" { - interface H3EventContext { - auth: { - getCurrent: () => Promise<{ id: number; username: string } | null>; - requireUser: () => Promise<{ id: number; username: string }>; - }; - config: { - getGlobal: (key: K) => Promise>; - getUser: (key: K) => Promise | undefined>; - get: (key: K) => Promise>; - }; - } -} - -export {};