From cad7d54e834be30f08cf6efbd33b59d054f229f9 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 24 Oct 2026 23:52:37 +0200 Subject: [PATCH] feat(shared): the demo account's addresses live in one place for both sides The client is about to lock settings sections for the shared demo account, and it has to ask the same question the server does. DEMO_ACCOUNT_EMAILS and isDemoAccountEmail now sit in @trek/shared, and the server's DEMO_EMAILS is built from them instead of spelling the two addresses a second time. --- server/src/nest/common/demo.ts | 4 +++- shared/src/demo/demo-account.spec.ts | 19 +++++++++++++++++++ shared/src/demo/demo-account.ts | 14 ++++++++++++++ shared/src/index.ts | 3 +++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 shared/src/demo/demo-account.spec.ts create mode 100644 shared/src/demo/demo-account.ts diff --git a/server/src/nest/common/demo.ts b/server/src/nest/common/demo.ts index eb5648cad..15c812e33 100644 --- a/server/src/nest/common/demo.ts +++ b/server/src/nest/common/demo.ts @@ -1,3 +1,5 @@ +import { DEMO_ACCOUNT_EMAILS } from '@trek/shared'; + // Central registry of demo-user email addresses. // // Historical: the demo account was seeded as "demo@trek.app" (see @@ -23,7 +25,7 @@ export const DEMO_PASS = 'demo12345'; * Includes the historical `demo@nomad.app` identifier so instances that * upgraded in place without resetting the DB still hit demo-mode guards. */ -export const DEMO_EMAILS: ReadonlySet = new Set([DEMO_EMAIL_PRIMARY, 'demo@nomad.app']); +export const DEMO_EMAILS: ReadonlySet = new Set(DEMO_ACCOUNT_EMAILS); export function isDemoEmail(email: string | null | undefined): boolean { return !!email && DEMO_EMAILS.has(email); diff --git a/shared/src/demo/demo-account.spec.ts b/shared/src/demo/demo-account.spec.ts new file mode 100644 index 000000000..dc49b616c --- /dev/null +++ b/shared/src/demo/demo-account.spec.ts @@ -0,0 +1,19 @@ +import { DEMO_ACCOUNT_EMAILS, isDemoAccountEmail } from './demo-account'; + +import { describe, expect, it } from 'vitest'; + +describe('isDemoAccountEmail', () => { + it('knows the current and the pre-rename demo address', () => { + expect(DEMO_ACCOUNT_EMAILS).toEqual(['demo@trek.app', 'demo@nomad.app']); + expect(isDemoAccountEmail('demo@trek.app')).toBe(true); + expect(isDemoAccountEmail('demo@nomad.app')).toBe(true); + }); + + it('is false for every other address and for none at all', () => { + expect(isDemoAccountEmail('admin@trek.app')).toBe(false); + expect(isDemoAccountEmail('DEMO@trek.app')).toBe(false); + expect(isDemoAccountEmail('')).toBe(false); + expect(isDemoAccountEmail(null)).toBe(false); + expect(isDemoAccountEmail(undefined)).toBe(false); + }); +}); diff --git a/shared/src/demo/demo-account.ts b/shared/src/demo/demo-account.ts new file mode 100644 index 000000000..b82a8d809 --- /dev/null +++ b/shared/src/demo/demo-account.ts @@ -0,0 +1,14 @@ +/** + * The shared account every visitor of a demo instance signs in as. + * + * Both sides ask the same question: the server refuses the writes this + * account may not make, and the client shows the same sections under a demo + * lock. `demo@nomad.app` is the address the account had before the rename, so + * an instance upgraded in place still treats it as the demo account. + */ +export const DEMO_ACCOUNT_EMAILS: readonly string[] = ['demo@trek.app', 'demo@nomad.app']; + +/** Whether this address is the demo account's. Instance demo mode is asked apart. */ +export function isDemoAccountEmail(email: string | null | undefined): boolean { + return !!email && DEMO_ACCOUNT_EMAILS.includes(email); +} diff --git a/shared/src/index.ts b/shared/src/index.ts index d450cedd9..18f25c0bf 100644 --- a/shared/src/index.ts +++ b/shared/src/index.ts @@ -280,6 +280,9 @@ export * from './money/money'; // Trip permission catalog (keys, levels, defaults) and the rule that decides a check. export * from './permissions/permissions'; +// The shared account visitors of a demo instance sign in as. +export * from './demo/demo-account'; + // Via ferratas around a trip, from OpenStreetMap through Overpass (GET /api/trips/:tripId/ferratas). export * from './ferratas/ferratas.schema'; // The 0.05 degree tile grid both ends load, cache and persist the layer on.