Skip to content

Commit 055f20e

Browse files
committed
dev-demo: add agent user to the dev-demo to prevent burning tokens on login attempts
1 parent 5b8183a commit 055f20e

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎AGENTS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Howeverer internally (e.g. in `codeInjector`) adminforth still supports both `np
1010

1111
Never patch anything in `spa_tmp` (e.g. `/tmp/adminforth/<app>/spa_tmp`): no file edits, no `pnpm install`, no own vite or other commands there. `codeInjector` generates it from `adminforth/spa` and the custom components of the app and its plugins, a manual install there drops the packages it adds for plugins. After a change in `spa/package.json` or `spa/tailwind.config.js` the running app breaks until a restart, tell the user to restart it.
1212

13+
## Dev demo login
14+
15+
To log in to the local dev-demo (`http://localhost:3123`) use `agent` as username and `agent` as password. The user is created on start and is exempt from 2FA. Do not use `adminforth`, it may have 2FA set up in the local database.
16+
1317
## Package names rules
1418

1519

‎dev-demo/index.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import mcpAuthSecretsResource from './resources/mcpAuthSecrets.js';
4444
import { logger } from '../adminforth/modules/logger.js';
4545

4646
import { globalPlugins } from './globalPlugins.js';
47+
import { AGENT_USER_EMAIL } from './utils.js';
4748

4849
const ADMIN_BASE_URL = '';
4950

@@ -460,6 +461,13 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
460461
role: 'superadmin',
461462
});
462463
}
464+
if (await admin.resource('adminuser').count(Filters.EQ('email', AGENT_USER_EMAIL)) === 0) {
465+
await admin.resource('adminuser').create({
466+
email: AGENT_USER_EMAIL,
467+
password_hash: await AdminForth.Utils.generatePasswordHash(AGENT_USER_EMAIL),
468+
role: 'superadmin',
469+
});
470+
}
463471
if (await admin.resource('cars_sl').count() === 0) {
464472
for (let i = 0; i < 100; i++) {
465473
const engine_type = ENGINE_TYPES[Math.floor(Math.random() * ENGINE_TYPES.length)].value;

‎dev-demo/resources/configs/twoFactorAuthPluginConfig.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import TwoFactorsAuthPlugin from "../../../plugins/adminforth-two-factors-auth/index.js";
22
import KeyValueAdapterRam from '../../../adapters/adminforth-key-value-adapter-ram/index.js';
33
import type { AdminUser } from '../../../adminforth/index.js';
4+
import { AGENT_USER_EMAIL } from '../../utils.js';
45

56

67

@@ -9,6 +10,7 @@ export default new TwoFactorsAuthPlugin (
910
twoFaSecretFieldName: 'secret2fa',
1011
timeStepWindow: 1,
1112
stepUpMfaGracePeriodSeconds: 300,
13+
usersFilterToApply: (adminUser: AdminUser) => adminUser.dbUser.email !== AGENT_USER_EMAIL,
1214
usersFilterToAllowSkipSetup: (adminUser: AdminUser) => {
1315
// allow skip setup 2FA for users which email is 'adminforth' or 'adminguest'
1416
return (true);

‎dev-demo/utils.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import ResourceKeyValueAdapter from '../adapters/adminforth-key-value-adapter-re
44
import RAMKeyValueAdapter from '../adapters/adminforth-key-value-adapter-ram/index.js';
55
import AdminForthAdapterS3Storage from '../adapters/adminforth-storage-adapter-amazon-s3/index.js';
66

7+
// local user for coding agents, its password is the same as the email, it is exempt from 2FA
8+
export const AGENT_USER_EMAIL = 'agent';
9+
710
export const levelDbAdapter = new LevelDBKeyValueAdapter({
811
dbPath: './testdb',
912
});

0 commit comments

Comments
 (0)