Skip to content

Commit 107d5da

Browse files
Copilothotlong
andcommitted
feat: add plugin-auth to app-host for Vercel deployment
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent e14a729 commit 107d5da

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

examples/app-host/objectstack.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { defineStack } from '@objectstack/spec';
44
import { AppPlugin, DriverPlugin } from '@objectstack/runtime';
55
import { ObjectQLPlugin } from '@objectstack/objectql';
66
import { InMemoryDriver } from '@objectstack/driver-memory';
7+
import { AuthPlugin } from '@objectstack/plugin-auth';
78
import CrmApp from '../app-crm/objectstack.config';
89
import TodoApp from '../app-todo/objectstack.config';
910
import BiPluginManifest from '../plugin-bi/objectstack.config';
@@ -12,6 +13,15 @@ import BiPluginManifest from '../plugin-bi/objectstack.config';
1213
// This project acts as a "Platform Server" that loads multiple apps and plugins.
1314
// It effectively replaces the manual composition in `src/index.ts`.
1415

16+
// Shared authentication plugin — reads secrets from environment variables so the
17+
// same config works both locally and on Vercel (where VERCEL_URL is injected).
18+
const authPlugin = new AuthPlugin({
19+
secret: process.env.AUTH_SECRET ?? 'dev-secret-please-change-in-production-min-32-chars',
20+
baseUrl: process.env.NEXT_PUBLIC_BASE_URL ?? (process.env.VERCEL_URL
21+
? `https://${process.env.VERCEL_URL}`
22+
: 'http://localhost:3000'),
23+
});
24+
1525
export default defineStack({
1626
manifest: {
1727
id: 'app-host',
@@ -27,6 +37,8 @@ export default defineStack({
2737
new ObjectQLPlugin(),
2838
// Register Default Driver (Memory)
2939
new DriverPlugin(new InMemoryDriver()),
40+
// Authentication — required for production (Vercel) deployments
41+
authPlugin,
3042
// Wrap Manifests/Stacks in AppPlugin adapter
3143
new AppPlugin(CrmApp),
3244
new AppPlugin(TodoApp),
@@ -90,6 +102,7 @@ export const PreviewHostExample = defineStack({
90102
plugins: [
91103
new ObjectQLPlugin(),
92104
new DriverPlugin(new InMemoryDriver()),
105+
authPlugin,
93106
new AppPlugin(CrmApp),
94107
new AppPlugin(TodoApp),
95108
new AppPlugin(BiPluginManifest)

examples/app-host/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@objectstack/metadata": "workspace:*",
2020
"@objectstack/objectql": "workspace:*",
2121
"@example/plugin-bi": "workspace:*",
22+
"@objectstack/plugin-auth": "workspace:*",
2223
"@objectstack/plugin-hono-server": "workspace:*",
2324
"@objectstack/runtime": "workspace:*",
2425
"@objectstack/spec": "workspace:*"

examples/app-host/vercel.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://openapi.vercel.sh/vercel.json",
3+
"installCommand": "cd ../.. && pnpm install",
4+
"buildCommand": "cd ../.. && pnpm turbo run build --filter=@example/app-host",
5+
"outputDirectory": "dist",
6+
"env": {
7+
"AUTH_SECRET": "@auth_secret",
8+
"VERCEL_URL": "@vercel_url"
9+
}
10+
}

0 commit comments

Comments
 (0)