Skip to content

Commit f6fe8a0

Browse files
Add AuthPlugin to demo/mock environment to restore Setup App menu
- Import and register AuthPlugin in createKernel.ts before SetupPlugin - Provide mock auth config for demo environment (secret + baseUrl) - Ensure correct plugin order to avoid 'sys' namespace collision - Remove duplicate setupAppConfig registration from browser.ts, server.ts, and test files - Replace setupAppConfig with AuthPlugin + SetupPlugin in console config - All i18n tests pass successfully Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/ad7046f8-9652-4470-b9fa-c1dbdb78ab9a Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent 3a60f3c commit f6fe8a0

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

apps/console/objectstack.config.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const require = createRequire(import.meta.url);
44
// @ts-ignore
55
globalThis.require = require;
66

7-
import { sharedConfig, appConfigs, setupAppConfig } from './objectstack.shared';
7+
import { sharedConfig, appConfigs } from './objectstack.shared';
88

99
// @ts-ignore
1010
import * as MSWPluginPkg from '@objectstack/plugin-msw';
@@ -13,6 +13,10 @@ import * as ObjectQLPluginPkg from '@objectstack/objectql';
1313
// @ts-ignore
1414
import * as HonoServerPluginPkg from '@objectstack/plugin-hono-server';
1515
// @ts-ignore
16+
import * as AuthPluginPkg from '@objectstack/plugin-auth';
17+
// @ts-ignore
18+
import * as SetupPluginPkg from '@objectstack/plugin-setup';
19+
// @ts-ignore
1620
import * as DriverMemoryPkg from '@objectstack/driver-memory';
1721
// @ts-ignore
1822
import * as RuntimePkg from '@objectstack/runtime';
@@ -25,6 +29,8 @@ const InMemoryDriver = DriverMemoryPkg.InMemoryDriver || (DriverMemoryPkg as any
2529
const DriverPlugin = RuntimePkg.DriverPlugin || (RuntimePkg as any).default?.DriverPlugin || (RuntimePkg as any).default;
2630
const AppPlugin = RuntimePkg.AppPlugin || (RuntimePkg as any).default?.AppPlugin || (RuntimePkg as any).default;
2731
const HonoServerPlugin = HonoServerPluginPkg.HonoServerPlugin || (HonoServerPluginPkg as any).default?.HonoServerPlugin || (HonoServerPluginPkg as any).default;
32+
const AuthPlugin = AuthPluginPkg.AuthPlugin || (AuthPluginPkg as any).default?.AuthPlugin || (AuthPluginPkg as any).default;
33+
const SetupPlugin = SetupPluginPkg.SetupPlugin || (SetupPluginPkg as any).default?.SetupPlugin || (SetupPluginPkg as any).default;
2834
const createMemoryI18n = CorePkg.createMemoryI18n || (CorePkg as any).default?.createMemoryI18n;
2935

3036
import { ConsolePlugin } from './plugin';
@@ -70,15 +76,23 @@ class MemoryI18nPlugin {
7076
*
7177
* MemoryI18nPlugin MUST come before AppPlugin so that the i18n service
7278
* exists when AppPlugin.start() → loadTranslations() runs.
79+
*
80+
* AuthPlugin before SetupPlugin: both use namespace 'sys', and the
81+
* ObjectQL registry requires the package that owns objects (AuthPlugin →
82+
* com.objectstack.system) to register first.
7383
*/
7484
const plugins: any[] = [
7585
new MemoryI18nPlugin(),
7686
new ObjectQLPlugin(),
7787
new DriverPlugin(new InMemoryDriver(), 'memory'),
7888
// Each example stack loaded as an independent AppPlugin
7989
...appConfigs.map((config: any) => new AppPlugin(config)),
80-
// Setup App registered via AppPlugin so ObjectQLPlugin discovers it
81-
new AppPlugin(setupAppConfig),
90+
// Auth & Setup plugins (replaces setupAppConfig)
91+
new AuthPlugin({
92+
secret: process.env.AUTH_SECRET || 'objectui-server-secret',
93+
baseUrl: process.env.BASE_URL || 'http://localhost:3000',
94+
}),
95+
new SetupPlugin(),
8296
new HonoServerPlugin({ port: 3000 }),
8397
new ConsolePlugin(),
8498
];

apps/console/src/__tests__/i18n-translations.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
1313
import { setupServer } from 'msw/node';
1414
import { createKernel, type KernelResult } from '../mocks/createKernel';
1515
import { createAuthHandlers } from '../mocks/authHandlers';
16-
import { appConfigs, setupAppConfig } from '../../objectstack.shared';
16+
import { appConfigs } from '../../objectstack.shared';
1717
import { crmLocales } from '@object-ui/example-crm';
1818

1919
// Expected values from the CRM i18n bundles — avoid hard-coding in assertions
@@ -26,7 +26,8 @@ describe('i18n translations pipeline', () => {
2626

2727
beforeAll(async () => {
2828
result = await createKernel({
29-
appConfigs: [...appConfigs, setupAppConfig],
29+
// SetupPlugin is registered in createKernel, so no need for setupAppConfig here
30+
appConfigs: [...appConfigs],
3031
persistence: false,
3132
mswOptions: {
3233
enableBrowser: false,

apps/console/src/mocks/browser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { setupWorker } from 'msw/browser';
1616
import { ObjectKernel } from '@objectstack/runtime';
1717
import { InMemoryDriver } from '@objectstack/driver-memory';
1818
import type { MSWPlugin } from '@objectstack/plugin-msw';
19-
import { appConfigs, setupAppConfig, customReportsConfig } from '../../objectstack.shared';
19+
import { appConfigs, customReportsConfig } from '../../objectstack.shared';
2020
import { createKernel } from './createKernel';
2121
import { createAuthHandlers } from './authHandlers';
2222

@@ -43,7 +43,8 @@ export async function startMockServer() {
4343
if (import.meta.env.DEV) console.log('[MSW] Starting ObjectStack Runtime (Browser Mode)...');
4444

4545
const result = await createKernel({
46-
appConfigs: [...appConfigs, setupAppConfig, customReportsConfig],
46+
// SetupPlugin is registered in createKernel, so no need for setupAppConfig here
47+
appConfigs: [...appConfigs, customReportsConfig],
4748
mswOptions: {
4849
enableBrowser: false,
4950
baseUrl: '/api/v1',

apps/console/src/mocks/createKernel.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ObjectQLPlugin } from '@objectstack/objectql';
1717
import { InMemoryDriver, MemoryAnalyticsService } from '@objectstack/driver-memory';
1818
import { MSWPlugin } from '@objectstack/plugin-msw';
1919
import type { MSWPluginOptions } from '@objectstack/plugin-msw';
20+
import { AuthPlugin } from '@objectstack/plugin-auth';
2021
import { SetupPlugin } from '@objectstack/plugin-setup';
2122
import type { Cube } from '@objectstack/spec/data';
2223
import { http, HttpResponse } from 'msw';
@@ -317,6 +318,15 @@ export async function createKernel(options: KernelOptions): Promise<KernelResult
317318
for (const config of configs) {
318319
await kernel.use(new AppPlugin(config));
319320
}
321+
// AuthPlugin before SetupPlugin: both use namespace 'sys', and the
322+
// ObjectQL registry requires the package that owns objects (AuthPlugin →
323+
// com.objectstack.system) to register first.
324+
await kernel.use(new AuthPlugin({
325+
secret: 'objectui-demo-secret',
326+
baseUrl: 'http://localhost:5173', // Vite dev server default
327+
}) as unknown as Plugin);
328+
// SetupPlugin registers setupNav during init and the merged Setup app
329+
// during start. Must come after AuthPlugin to avoid sys namespace collision.
320330
await kernel.use(new SetupPlugin() as unknown as Plugin);
321331

322332
// Register MemoryAnalyticsService so that HttpDispatcher can serve

apps/console/src/mocks/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ObjectKernel } from '@objectstack/runtime';
1616
import { InMemoryDriver } from '@objectstack/driver-memory';
1717
import { setupServer } from 'msw/node';
1818
import type { MSWPlugin } from '@objectstack/plugin-msw';
19-
import { appConfigs, setupAppConfig, customReportsConfig } from '../../objectstack.shared';
19+
import { appConfigs, customReportsConfig } from '../../objectstack.shared';
2020
import { createKernel } from './createKernel';
2121
import { createAuthHandlers } from './authHandlers';
2222

@@ -34,7 +34,8 @@ export async function startMockServer() {
3434
console.log('[MSW] Starting ObjectStack Runtime (Test Mode)...');
3535

3636
const result = await createKernel({
37-
appConfigs: [...appConfigs, setupAppConfig, customReportsConfig],
37+
// SetupPlugin is registered in createKernel, so no need for setupAppConfig here
38+
appConfigs: [...appConfigs, customReportsConfig],
3839
persistence: false,
3940
mswOptions: {
4041
enableBrowser: false,

0 commit comments

Comments
 (0)