From 13aa58e0e925b64348ddfd3e8d5f2b79db52ef2d Mon Sep 17 00:00:00 2001 From: 00Chaotic Date: Tue, 23 Apr 2024 16:39:33 +1000 Subject: [PATCH] feat: allow admin login using demo auth (#6808) This PR introduces a configuration option (`authentication.demoAllowAdminLogin`) that allows you to log in as admin when using demo authentication. To do this, use the username `admin`. ## About the changes The `admin` user currently cannot be accessed in `demo` authentication mode, as the auth mode requires only an email to log in, and the admin user is not created with an email. This change allows for logging in as the admin user only if an `AUTH_DEMO_ALLOW_ADMIN_LOGIN` is set to `true` (or the corresponding `authDemoAllowAdminLogin` config is enabled). Closes #6398 ### Important files [demo-authentication.ts](https://github.com/Unleash/unleash/compare/main...00Chaotic:unleash:feat/allow_admin_login_using_demo_auth?expand=1#diff-c166f00f0a8ca4425236b3bcba40a8a3bd07a98d067495a0a092eec26866c9f1R25) ## Discussion points Can continue discussion of [this comment](https://github.com/Unleash/unleash/pull/6447#issuecomment-2042405647) in this PR. --------- Co-authored-by: Thomas Heartman --- .../src/component/user/DemoAuth/DemoAuth.tsx | 2 +- .../__snapshots__/create-config.test.ts.snap | 1 + src/lib/create-config.test.ts | 5 ++ src/lib/create-config.ts | 4 + .../demo-authentication.e2e.test.ts | 73 +++++++++++++++++++ src/lib/middleware/demo-authentication.ts | 23 +++--- src/lib/services/user-service.ts | 6 ++ src/lib/types/option.ts | 1 + 8 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 src/lib/middleware/demo-authentication.e2e.test.ts diff --git a/frontend/src/component/user/DemoAuth/DemoAuth.tsx b/frontend/src/component/user/DemoAuth/DemoAuth.tsx index ff4054959f..de29cfc970 100644 --- a/frontend/src/component/user/DemoAuth/DemoAuth.tsx +++ b/frontend/src/component/user/DemoAuth/DemoAuth.tsx @@ -63,7 +63,7 @@ const DemoAuth: VFC = ({ authDetails, redirect }) => { id='email' data-testid={LOGIN_EMAIL_ID} required - type='email' + type={email === 'admin' ? 'text' : 'email'} />