Browse Source

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.
feat/auth-access-control
npmrun 2 days ago
parent
commit
12e892683e
  1. 11
      server/plugins/01.context.ts
  2. 17
      server/types/config-context.d.ts

11
server/plugins/01.context.ts

@ -7,6 +7,17 @@ if (import.meta.dev) {
console.log("plugin: 01.context"); console.log("plugin: 01.context");
} }
declare module "h3" {
interface H3EventContext {
auth: ReturnType<typeof createAuthContext>;
config: {
getGlobal: <K extends KnownConfigKey>(key: K) => Promise<KnownConfigValue<K>>;
getUser: <K extends KnownConfigKey>(key: K) => Promise<KnownConfigValue<K> | undefined>;
get: <K extends KnownConfigKey>(key: K) => Promise<KnownConfigValue<K>>;
};
}
}
export default defineNitroPlugin((nitroApp) => { export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook("request", (event) => { nitroApp.hooks.hook("request", (event) => {
const requestCache = new Map<string, Promise<unknown>>(); const requestCache = new Map<string, Promise<unknown>>();

17
server/types/config-context.d.ts

@ -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: <K extends KnownConfigKey>(key: K) => Promise<KnownConfigValue<K>>;
getUser: <K extends KnownConfigKey>(key: K) => Promise<KnownConfigValue<K> | undefined>;
get: <K extends KnownConfigKey>(key: K) => Promise<KnownConfigValue<K>>;
};
}
}
export {};
Loading…
Cancel
Save