Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

feat(shared): the demo account's addresses live in one place for both sides

Mauricecad7d54e834b
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 "[email protected]" (see
@@ -23,7 +25,7 @@ export const DEMO_PASS = 'demo12345';
* Includes the historical `[email protected]` identifier so instances that
* upgraded in place without resetting the DB still hit demo-mode guards.
*/
-export const DEMO_EMAILS: ReadonlySet<string> = new Set([DEMO_EMAIL_PRIMARY, '[email protected]']);
+export const DEMO_EMAILS: ReadonlySet<string> = 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(['[email protected]', '[email protected]']);
+ expect(isDemoAccountEmail('[email protected]')).toBe(true);
+ expect(isDemoAccountEmail('[email protected]')).toBe(true);
+ });
+
+ it('is false for every other address and for none at all', () => {
+ expect(isDemoAccountEmail('[email protected]')).toBe(false);
+ expect(isDemoAccountEmail('[email protected]')).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. `[email protected]` 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[] = ['[email protected]', '[email protected]'];
+
+/** 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.