From e6dc232aa224fd72c92924a6a62c40746fdbfcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kenneth=20Wu=C3=9Fmann?= Date: Tue, 27 Feb 2024 01:52:20 +0100 Subject: [PATCH] Only create superusers when not in demo mode --- src/server/lib/user/userService.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server/lib/user/userService.ts b/src/server/lib/user/userService.ts index 51b71f7..d14d43e 100644 --- a/src/server/lib/user/userService.ts +++ b/src/server/lib/user/userService.ts @@ -8,6 +8,7 @@ import { type RateLimitService } from "../rate-limit/rateLimitService"; import { type UserMe, type User } from "./user"; import { type UserListRequest } from "./userListRequest"; import { type UserChangePasswordRequest } from "./userChangePasswordRequest"; +import { env } from "~/env.mjs"; export class UserService { constructor( @@ -89,6 +90,7 @@ export class UserService { remoteAddress: string, request: UserRegisterRequest ): Promise => { + const isDemoMode = env.DEMO_MODE; const { email, password } = request; const sanitizedEmail = sanitizeEmail(email); const exists = await this.prisma.user.count({ @@ -138,7 +140,8 @@ export class UserService { data: { email: sanitizedEmail, password: await hashPassword(password), - role: totalUserCount === 0 ? UserRole.ADMIN : UserRole.USER, + role: + totalUserCount === 0 && !isDemoMode ? UserRole.ADMIN : UserRole.USER, }, }); this.logger.info("New user registered", {