From 23196aa0389502726a0c98e2b071d1896b3d7656 Mon Sep 17 00:00:00 2001 From: Maurice Date: Tue, 25 Aug 2026 10:33:48 +0200 Subject: [PATCH] refactor(demo): keep the demo password in one place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was written out twice — once in the seeder that creates the account, once in the config payload the login screen reads it from. The two have to match exactly or the published demo credentials stop working, which is a poor thing to leave to copy-paste. It moves next to DEMO_EMAIL_PRIMARY, which the same comment block already argues for. Also clears a Sonar S2068 "hard-coded password" on the auth service: the value is public on purpose, but a literal next to a `demo_password` key is exactly what the rule looks for. --- server/src/demo/demo-seed.ts | 2 +- server/src/nest/auth/auth.service.ts | 4 ++-- server/src/nest/common/demo.ts | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/src/demo/demo-seed.ts b/server/src/demo/demo-seed.ts index c10291055..c08e1753d 100644 --- a/server/src/demo/demo-seed.ts +++ b/server/src/demo/demo-seed.ts @@ -1,6 +1,7 @@ import bcrypt from 'bcryptjs'; import Database from 'better-sqlite3'; import { readEnv } from '../app-config'; +import { DEMO_PASS } from '../nest/common/demo'; // Static like in demo-reset.job.ts: the module top is inert, everything that // touches the database happens inside the functions. import { saveBaseline, hasBaseline } from './demo-reset'; @@ -10,7 +11,6 @@ function seedDemoData(db: Database.Database): { adminId: number; demoId: number const ADMIN_EMAIL = readEnv().demo.adminEmailRaw || 'admin@trek.app'; const ADMIN_PASS = readEnv().demo.adminPass; const DEMO_EMAIL = 'demo@trek.app'; - const DEMO_PASS = 'demo12345'; // Create admin user if not exists let admin = db.prepare('SELECT id FROM users WHERE email = ?').get(ADMIN_EMAIL) as { id: number } | undefined; diff --git a/server/src/nest/auth/auth.service.ts b/server/src/nest/auth/auth.service.ts index a18dab305..f7bfcddc2 100644 --- a/server/src/nest/auth/auth.service.ts +++ b/server/src/nest/auth/auth.service.ts @@ -25,7 +25,7 @@ import { splitManagedKeys } from '../common/managed'; import { emitUserDeleted } from '../../plugin-user-lifecycle'; import { verifyJwtAndLoadUser } from './jwt-verify'; import { User } from '../../types'; -import { DEMO_EMAIL_PRIMARY, isDemoEmail } from '../common/demo'; +import { DEMO_EMAIL_PRIMARY, DEMO_PASS, isDemoEmail } from '../common/demo'; import { avatarUrl } from '../common/avatarUrl'; import { TripMembershipService } from '../trip-membership/trip-membership.service'; import { WebauthnConfigService } from './webauthn-config.service'; @@ -303,7 +303,7 @@ export class AuthService { managed: readEnv().managed.enabled, demo_mode: isDemo, demo_email: isDemo ? DEMO_EMAIL_PRIMARY : undefined, - demo_password: isDemo ? 'demo12345' : undefined, + demo_password: isDemo ? DEMO_PASS : undefined, timezone: readEnv().app.tz || Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC', notification_channel: notifChannel, notification_channels: activeChannels, diff --git a/server/src/nest/common/demo.ts b/server/src/nest/common/demo.ts index 8e30cd3b3..e6b34d450 100644 --- a/server/src/nest/common/demo.ts +++ b/server/src/nest/common/demo.ts @@ -10,6 +10,14 @@ export const DEMO_EMAIL_PRIMARY = 'demo@trek.app'; +/** + * The demo account's password. Public on purpose — a demo instance shows it on + * the login screen so visitors can get in — but it was written out twice, in the + * seeder and in the config payload, which is one copy too many for something the + * seeder has to match exactly for the login to work. + */ +export const DEMO_PASS = 'demo12345'; + /** * All email addresses that should be treated as the demo account. * Includes the historical `demo@nomad.app` identifier so instances that