mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
refactor(demo): keep the demo password in one place
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user