{"record":{"id":"1a3c532eb0f9816c","repo":"immich-app/immich","slug":"the-first-registered-account-must-the-administrato","errorCode":null,"errorMessage":"The first registered account must the administrator.","messagePattern":"The first registered account must the administrator\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"server/src/services/base.service.ts","lineNumber":305,"sourceCode":"  }\n\n  async requireSetupAvailable(): Promise<void> {\n    if (!(await this.isSetupAvailable())) {\n      throw new BadRequestException('Admin setup is not available');\n    }\n  }\n\n  async createUser(dto: Insertable<UserTable> & { email: string }): Promise<UserAdmin> {\n    const exists = await this.userRepository.getByEmail(dto.email);\n    if (exists) {\n      this.logger.debug('User creation rejected: user already exists');\n      throw new BadRequestException('Email is not available');\n    }\n\n    if (!dto.isAdmin) {\n      const localAdmin = await this.userRepository.getAdmin();\n      if (!localAdmin) {\n        throw new BadRequestException('The first registered account must the administrator.');\n      }\n    }\n\n    const payload: Insertable<UserTable> = { ...dto };\n    if (payload.password) {\n      payload.password = await this.cryptoRepository.hashBcrypt(payload.password, SALT_ROUNDS);\n    }\n    if (payload.storageLabel) {\n      payload.storageLabel = sanitize(payload.storageLabel.replaceAll('.', ''));\n    }\n\n    const user = await this.userRepository.create(payload);\n\n    await this.eventRepository.emit('UserCreate', user);\n\n    return user;\n  }\n}","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/immich-app/immich/blob/199723261c6ffa897fec8ccdaea6359e39c37cc3/server/src/services/base.service.ts#L287-L323","documentation":"Thrown by BaseService.createUser when a non-admin user is being created (dto.isAdmin is false) but userRepository.getAdmin() returns nothing. Immich requires the very first account to be the administrator, so creating a regular user before any admin exists is blocked.","triggerScenarios":"An attempt to register/create a normal (non-admin) account on a fresh installation that has no admin user yet.","commonSituations":"First-run registration submitted with isAdmin=false; a provisioning script that creates test users before bootstrapping the admin; DB reset that wiped the admin but the next request tries to add a non-admin.","solutions":["Make the first user-creation call on a fresh system set isAdmin: true.","Run the admin bootstrap/onboarding step before any non-admin provisioning.","If an admin was accidentally deleted, restore it or re-run setup with isAdmin=true before adding users."],"exampleFix":"// before\nawait userService.createUser({ email, isAdmin: false, ...rest });\n\n// after\nconst hasAdmin = await userRepository.hasAdmin();\nawait userService.createUser({ email, isAdmin: !hasAdmin, ...rest });","handlingStrategy":"validation","validationCode":"const isFirstUser = !(await userRepository.hasAdmin());\nawait userService.createUser({ ...dto, isAdmin: isFirstUser });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make first-run registration force isAdmin=true automatically.","Run the admin bootstrap before any non-admin provisioning scripts.","If the admin was deleted, re-bootstrap before adding users."],"tags":["user","admin","onboarding","bad-request"],"backgroundTag":null,"analyzedSha":"199723261c6ffa897fec8ccdaea6359e39c37cc3","analyzedAt":"2026-08-12T04:54:27.085Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}