Script: nifty_fifty_bank_nifty_NodeJS/scripts/createAdminUser.ts

Purpose

Creates a single admin user in MongoDB if one does not already exist with the configured email.

Default credentials

Read from environment: User document fields:
  • role: 'admin'
  • isActive: true
  • isMfaEnabled: false

Run

From nifty_fifty_bank_nifty_NodeJS:
Or via npm script if defined in package.json.

Prerequisites

  • MongoDB running at MONGO_URI
  • .env loaded with MONGO_URI, ADMIN_EMAIL, ADMIN_PASSWORD

Behavior

  1. Connect to MongoDB
  2. If email exists → abort with error
  3. Else UserModel.create(adminUser)
  4. Log email and remind to change password
  5. Disconnect and exit

After creation

  1. Set VITE_APP_EMAIL / password for dev login (optional)
  2. Log in at /login
  3. Change password via profile or admin edit
  4. Enable MFA for production admins