Skip to content

Commit 55a6309

Browse files
committed
updated self host vars, reduced the number of required env vars
1 parent 1b5b38e commit 55a6309

File tree

9 files changed

+181
-163
lines changed

9 files changed

+181
-163
lines changed

apps/backend/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Basic
22
NEXT_PUBLIC_STACK_API_URL=# the base URL of Stack's backend/API. For local development, this is `http://localhost:8102`; for the managed service, this is `https://api.stack-auth.com`.
33
NEXT_PUBLIC_STACK_DASHBOARD_URL=# the URL of Stack's dashboard. For local development, this is `http://localhost:8101`; for the managed service, this is `https://app.stack-auth.com`.
4-
STACK_SERVER_SECRET=# a random, unguessable secret key generated by `pnpm generate-keys`
4+
STACK_SECRET_SERVER_KEY=# a random, unguessable secret key generated by `pnpm generate-keys`
55

66
# seed script settings
77
STACK_SEED_INTERNAL_PROJECT_SIGN_UP_ENABLED=# true to add OTP auth to the dashboard when seeding

apps/backend/prisma/seed.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ async function seed() {
1818
const dashboardDomain = process.env.NEXT_PUBLIC_STACK_DASHBOARD_URL;
1919
const oauthProviderIds = process.env.STACK_SEED_INTERNAL_PROJECT_OAUTH_PROVIDERS?.split(',') ?? [];
2020
const otpEnabled = process.env.STACK_SEED_INTERNAL_PROJECT_OTP_ENABLED === 'true';
21-
const signUpEnabled = process.env.STACK_SEED_INTERNAL_PROJECT_SIGN_UP_ENABLED === 'true';
21+
const signUpEnabled = process.env.STACK_SEED_INTERNAL_PROJECT_SIGN_UP_DISABLED !== 'true';
2222
const allowLocalhost = process.env.STACK_SEED_INTERNAL_PROJECT_ALLOW_LOCALHOST === 'true';
2323
const clientTeamCreation = process.env.STACK_SEED_INTERNAL_PROJECT_CLIENT_TEAM_CREATION === 'true';
2424

25+
const apiKeyId = '3142e763-b230-44b5-8636-aa62f7489c26';
26+
const defaultUserId = '33e7c043-d2d1-4187-acd3-f91b5ed64b46';
27+
2528
let internalProject = await prisma.project.findUnique({
2629
where: {
2730
id: 'internal',
@@ -38,20 +41,9 @@ async function seed() {
3841
displayName: 'Stack Dashboard',
3942
description: 'Stack\'s admin dashboard',
4043
isProductionMode: false,
41-
apiKeySets: {
42-
create: [{
43-
description: "Internal API key set",
44-
// These keys must match the values used in the Stack dashboard env to be able to login via the UI.
45-
publishableClientKey: process.env.STACK_SEED_INTERNAL_PROJECT_PUBLISHABLE_CLIENT_KEY || throwErr('STACK_SEED_INTERNAL_PROJECT_PUBLISHABLE_CLIENT_KEY is not set'),
46-
secretServerKey: process.env.STACK_SEED_INTERNAL_PROJECT_SECRET_SERVER_KEY || throwErr('STACK_SEED_INTERNAL_PROJECT_SECRET_SERVER_KEY is not set'),
47-
superSecretAdminKey: process.env.STACK_SEED_INTERNAL_PROJECT_SUPER_SECRET_ADMIN_KEY || throwErr('STACK_SEED_INTERNAL_PROJECT_SUPER_SECRET_ADMIN_KEY is not set'),
48-
expiresAt: new Date('2099-12-31T23:59:59Z'),
49-
}],
50-
},
5144
config: {
5245
create: {
5346
allowLocalhost: true,
54-
signUpEnabled,
5547
emailServiceConfig: {
5648
create: {
5749
proxiedEmailServiceConfig: {
@@ -123,14 +115,42 @@ async function seed() {
123115
console.log('Internal project created');
124116
}
125117

118+
if (internalProject.config.signUpEnabled !== signUpEnabled) {
119+
await prisma.projectConfig.update({
120+
where: {
121+
id: internalProject.configId,
122+
},
123+
data: {
124+
signUpEnabled,
125+
}
126+
});
127+
128+
console.log(`Updated signUpEnabled for internal project: ${signUpEnabled}`);
129+
}
130+
131+
await prisma.apiKeySet.upsert({
132+
where: { projectId_id: { projectId: 'internal', id: apiKeyId } },
133+
update: {},
134+
create: {
135+
id: apiKeyId,
136+
projectId: 'internal',
137+
description: "Internal API key set",
138+
// These keys must match the values used in the Stack dashboard env to be able to login via the UI.
139+
publishableClientKey: process.env.STACK_SEED_INTERNAL_PROJECT_PUBLISHABLE_CLIENT_KEY || throwErr('STACK_SEED_INTERNAL_PROJECT_PUBLISHABLE_CLIENT_KEY is not set'),
140+
secretServerKey: process.env.STACK_SEED_INTERNAL_PROJECT_SECRET_SERVER_KEY || throwErr('STACK_SEED_INTERNAL_PROJECT_SECRET_SERVER_KEY is not set'),
141+
superSecretAdminKey: process.env.STACK_SEED_INTERNAL_PROJECT_SUPER_SECRET_ADMIN_KEY || throwErr('STACK_SEED_INTERNAL_PROJECT_SUPER_SECRET_ADMIN_KEY is not set'),
142+
expiresAt: new Date('2099-12-31T23:59:59Z'),
143+
}
144+
});
145+
126146
// Create optional default admin user if credentials are provided.
127147
// This user will be able to login to the dashboard with both email/password and magic link.
128148
if ((adminEmail && adminPassword) || adminGithubId) {
129149
await prisma.$transaction(async (tx) => {
130150
const oldAdminUser = await tx.projectUser.findFirst({
131151
where: {
132152
projectId: 'internal',
133-
projectUserId: '33e7c043-d2d1-4187-acd3-f91b5ed64b46'
153+
projectUserId: defaultUserId
134154
}
135155
});
136156

@@ -140,7 +160,7 @@ async function seed() {
140160
const newUser = await tx.projectUser.create({
141161
data: {
142162
displayName: 'Administrator (created by seed script)',
143-
projectUserId: '33e7c043-d2d1-4187-acd3-f91b5ed64b46',
163+
projectUserId: defaultUserId,
144164
projectId: 'internal',
145165
serverMetadata: adminInternalAccess
146166
? { managedProjectIds: ['internal'] }

docker/server/.env

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
NEXT_PUBLIC_STACK_API_URL=# https://your-backend-domain.com
22
NEXT_PUBLIC_STACK_DASHBOARD_URL=# https://your-dashboard-domain.com, this will be added as a trusted domain by the seed script
3-
STACK_SEED_INTERNAL_PROJECT_ALLOW_LOCALHOST=# if true, the internal dashboard project will allow localhost as a trusted domain. Do not set this to true in production.
43

54
STACK_DATABASE_CONNECTION_STRING=# postgres connection string with pooler
65
STACK_DIRECT_DATABASE_CONNECTION_STRING=# postgres direct connection string
76

8-
NEXT_PUBLIC_STACK_PROJECT_ID=internal
9-
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=# a secure random string
10-
STACK_SECRET_SERVER_KEY=# a secure random string
117
STACK_SERVER_SECRET=# a 32 bytes base64url encoded random string, used for JWT encryption. can be generated with `pnpm generate-keys`
128

139
# seed script settings
@@ -33,5 +29,5 @@ STACK_SVIX_SERVER_URL=# this is only needed if you self-host the Svix service
3329
STACK_SVIX_API_KEY=
3430

3531

36-
STACK_RUN_MIGRATIONS=true
37-
STACK_RUN_SEED_SCRIPT=true
32+
STACK_SKIP_MIGRATIONS=# true to skip prisma migrations
33+
STACK_SKIP_SEED_SCRIPT=# true to skip the seed script

docker/server/.env.example

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ NEXT_PUBLIC_STACK_DASHBOARD_URL=http://localhost:8101
44
STACK_DATABASE_CONNECTION_STRING=postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@host.docker.internal:5432/stackframe
55
STACK_DIRECT_DATABASE_CONNECTION_STRING=postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@host.docker.internal:5432/stackframe
66

7-
STACK_SEED_INTERNAL_PROJECT_PUBLISHABLE_CLIENT_KEY=this-publishable-client-key-is-for-local-development-only
8-
STACK_SEED_INTERNAL_PROJECT_SECRET_SERVER_KEY=this-secret-server-key-is-for-local-development-only
9-
STACK_SEED_INTERNAL_PROJECT_SUPER_SECRET_ADMIN_KEY=23-wuNpik0gIW4mruTz25rbIvhuuvZFrLOLtL7J4tyo
7+
STACK_SERVER_SECRET=23-wuNpik0gIW4mruTz25rbIvhuuvZFrLOLtL7J4tyo
8+
109
STACK_SEED_INTERNAL_PROJECT_ALLOW_LOCALHOST=true
11-
STACK_SEED_INTERNAL_PROJECT_USER_EMAIL=admin@email.com
12-
STACK_SEED_INTERNAL_PROJECT_USER_PASSWORD=password
13-
STACK_SEED_INTERNAL_PROJECT_USER_INTERNAL_ACCESS=false
10+
STACK_SEED_INTERNAL_PROJECT_SIGN_UP_ENABLED=true
1411

1512
STACK_RUN_MIGRATIONS=true
1613
STACK_RUN_SEED_SCRIPT=true

docker/server/entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@
22

33
set -e
44

5+
export STACK_SEED_INTERNAL_PROJECT_PUBLISHABLE_CLIENT_KEY=$(openssl rand -base64 32)
6+
export STACK_SEED_INTERNAL_PROJECT_SECRET_SERVER_KEY=$(openssl rand -base64 32)
7+
export STACK_SEED_INTERNAL_PROJECT_SUPER_SECRET_ADMIN_KEY=$(openssl rand -base64 32)
8+
59
export NEXT_PUBLIC_STACK_PROJECT_ID=internal
610
export NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=${STACK_SEED_INTERNAL_PROJECT_PUBLISHABLE_CLIENT_KEY}
711
export STACK_SECRET_SERVER_KEY=${STACK_SEED_INTERNAL_PROJECT_SECRET_SERVER_KEY}
812
export STACK_SUPER_SECRET_ADMIN_KEY=${STACK_SEED_INTERNAL_PROJECT_SUPER_SECRET_ADMIN_KEY}
913

10-
if [ "$STACK_RUN_MIGRATIONS" = "true" ]; then
14+
if [ "$STACK_SKIP_MIGRATIONS" = "true" ]; then
15+
echo "Skipping migrations."
16+
else
1117
echo "Running migrations..."
1218
prisma migrate deploy --schema=./apps/backend/prisma/schema.prisma
13-
else
14-
echo "Skipping migrations."
1519
fi
1620

17-
if [ "$STACK_RUN_SEED_SCRIPT" = "true" ]; then
21+
if [ "$STACK_SKIP_SEED_SCRIPT" = "true" ]; then
22+
echo "Skipping seed script."
23+
else
1824
echo "Running seed script..."
1925
cd apps/backend
2026
node seed.js
2127
cd ../..
22-
else
23-
echo "Skipping seed script."
2428
fi
2529

2630
# Start backend and dashboard in parallel

examples/demo/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
NEXT_PUBLIC_STACK_API_URL=# enter your stack endpoint here, e.g. http://localhost:8102
22
NEXT_PUBLIC_STACK_PROJECT_ID=# enter your stack project id here
33
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=# enter your stack publishable client key here
4-
STACK_SECRET_SERVER_KEY=# enter your stack secret server key here

examples/demo/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
NEXT_PUBLIC_STACK_API_URL=http://localhost:8102
44
NEXT_PUBLIC_STACK_PROJECT_ID=internal
55
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=this-publishable-client-key-is-for-local-development-only
6-
STACK_SECRET_SERVER_KEY=this-secret-server-key-is-for-local-development-only
6+
STACK_SECRET_SERVER_KEY=this-secret-server-key-is-for-local-development-only

examples/supabase/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "2.6.34",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev --port 8115",
6+
"dev": "next dev --turbo --port 8103",
7+
"clean": "rimraf .next && rimraf node_modules",
78
"build": "next build",
89
"start": "next start"
910
},
@@ -12,7 +13,7 @@
1213
"@supabase/ssr": "latest",
1314
"@supabase/supabase-js": "latest",
1415
"jose": "^5.2.2",
15-
"next": "latest",
16+
"next": "^15.0.3",
1617
"react": "18.2.0",
1718
"react-dom": "18.2.0"
1819
},

0 commit comments

Comments
 (0)