fix: update

This commit is contained in:
xiongxiao
2026-01-13 17:26:38 +08:00
parent cedf3236b0
commit d86f4dc48f
5 changed files with 16 additions and 7 deletions

View File

@@ -13,5 +13,7 @@ export const cnb = useContextKey<CNB>('cnb', () => {
}) })
export const appId = nanoid(); export const appId = nanoid();
export const app = useContextKey<App>('app', () => { export const app = useContextKey<App>('app', () => {
return new App() return new App({
appId
})
}) })

View File

@@ -1,8 +1,15 @@
import { app, appId } from '@/agent/app.ts'; import { app, appId } from '../app.ts';
import './user/check.ts' import './user/check.ts'
import { isEqual } from 'es-toolkit'
/**
* 验证上下文中的 App ID 是否与指定的 App ID 匹配
* @param {any} ctx - 上下文对象,可能包含 appId 属性
* @param {string} appId - 需要验证的目标 App ID
* @returns {boolean} 如果 ctx 中包含 appId 且匹配则返回 true否则返回 false
* @throws {Error} 如果 ctx 中包含 appId 但不匹配,则抛出 403 错误
*/
const checkAppId = (ctx: any, appId: string) => { const checkAppId = (ctx: any, appId: string) => {
const _appId = ctx?.appId; const _appId = ctx?.app?.appId;
if (_appId) { if (_appId) {
if (_appId !== appId) { if (_appId !== appId) {
ctx.throw(403, 'Invalid App ID'); ctx.throw(403, 'Invalid App ID');

View File

@@ -1,4 +1,4 @@
import { app, cnb } from '@/agent/app.ts'; import { app, cnb } from '../../app.ts';
app.route({ app.route({
path: 'cnb', path: 'cnb',

View File

@@ -1,4 +1,4 @@
import { app, cnb } from '@/agent/app.ts'; import { app, cnb } from '../../app.ts';
app.route({ app.route({

View File

@@ -1,4 +1,4 @@
import { app, cnb } from '@/agent/app.ts'; import { app, cnb } from '../../app.ts';
app.route({ app.route({
path: 'cnb', path: 'cnb',