mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
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.
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user