This guide explains how to create admin users in the AegisExpress Logistics system using different methods.
There are four ways to seed admin users:
- CLI Method: Seed a single admin via command line (for initial setup)
- REST Client Method: Easy visual method using VS Code (recommended for admins)
- API Single: Create one admin via API endpoint
- API Multiple: Create multiple admins via API endpoint
This method is used to create the first admin user when setting up the system.
- Set environment variables in
.envfile:
ADMIN_SEED_TOKEN=CHANGE_ME
ADMIN_EMAIL=owner@example.com
ADMIN_PASSWORD=Passw0rd!- Navigate to API directory:
cd api- Run the seeding command:
npm run dev -- --seed-admin
# OR
node server.js --seed-admin- Checks if
ADMIN_SEED_TOKENis set - Creates admin user with email and password from environment variables
- Prevents duplicate seeding using Redis flag
- Exits after seeding
✅ Admin seeded: owner@example.com
This is the easiest method for non-technical admins to seed new users.
- VS Code with "REST Client" extension installed
- Existing admin credentials (email and password)
- API server running on localhost:5000
-
Open the REST file:
- Navigate to
api/seedAdmin.restin VS Code - The file contains pre-written requests
- Navigate to
-
Update your credentials:
@email = your-admin@example.com @password = YourAdminPassword -
Login to get token:
- Click "Send Request" above the login request
- Copy the
tokenvalue from response
-
Update token variable:
@token = paste-your-jwt-token-here -
Seed new admin:
- Modify the email/password in the seeding request
- Click "Send Request" to create the admin
### Step 1: Login
POST http://localhost:5000/api/auth/login
Content-Type: application/json
{
"email": "owner@example.com",
"password": "Passw0rd!"
}
### Step 2: Seed Admin (after copying token)
POST http://localhost:5000/api/auth/seed-admins
Authorization: Bearer eyJhbGciOiJIUzI1NiI...
Content-Type: application/json
{
"admins": [
{
"email": "newadmin@example.com",
"password": "SecurePass123!",
"role": "admin"
}
]
}Create individual admin users via the API endpoint.
- Authentication: You need an existing admin token
- API Running: The server must be running
Endpoint: POST /api/auth/seed-admins
Headers:
Authorization: Bearer YOUR_JWT_TOKEN_FROM_LOGIN
Content-Type: application/json
Note: The JWT token is obtained by logging in first (see "Getting Admin Token" section below).
Body (Single Admin):
{
"admins": [
{
"email": "admin2@example.com",
"password": "SecurePass123!",
"role": "admin"
}
]
}curl -X POST http://localhost:5000/api/auth/seed-admins \
-H "Authorization: Bearer YOUR_JWT_TOKEN_FROM_LOGIN" \
-H "Content-Type: application/json" \
-d '{
"admins": [
{
"email": "admin2@example.com",
"password": "SecurePass123!",
"role": "admin"
}
]
}'Note: Replace YOUR_JWT_TOKEN_FROM_LOGIN with the actual JWT token you received when logging in.
- Method: POST
- URL:
http://localhost:5000/api/auth/seed-admins - Headers:
Authorization:Bearer YOUR_JWT_TOKEN_FROM_LOGINContent-Type:application/json
- Body: JSON with admins array
Important: Get the JWT token by logging in first!
Create multiple admin users in a single API call.
Body (Multiple Admins):
{
"admins": [
{
"email": "admin1@example.com",
"password": "SecurePass123!",
"role": "admin"
},
{
"email": "admin2@example.com",
"password": "AnotherPass456!",
"role": "admin"
},
{
"email": "manager@example.com",
"password": "ManagerPass789!",
"role": "admin"
}
]
}{
"success": true,
"message": "Admin seeding completed",
"results": [
{
"email": "admin1@example.com",
"status": "created",
"message": "Admin created successfully"
},
{
"email": "admin2@example.com",
"status": "created",
"message": "Admin created successfully"
},
{
"email": "existing@example.com",
"status": "skipped",
"message": "Admin already exists"
}
]
}All admin passwords must meet these criteria:
- At least 8 characters long
- Contains uppercase letters (A-Z)
- Contains lowercase letters (a-z)
- Contains numbers (0-9)
- Contains special characters (@$!%*?&)
SecurePass123!Admin@2024MyPassword$1
password(too simple)PASSWORD123(no special character)Pass@1(too short)
- Token Protection: The seeding endpoint requires admin authentication
- Duplicate Prevention: System prevents creating duplicate email accounts
- Password Hashing: All passwords are automatically hashed before storage
- Role Validation: Only "admin" role is supported for seeding
-
"No token provided"
- Solution: Include Authorization header with valid admin token
-
"Invalid email or password"
- Solution: Check password requirements and email format
-
"Admin already exists"
- Solution: Use different email or check existing users
-
"Failed to seed admins"
- Solution: Check server logs and database connection
- Login with existing admin:
curl -X POST http://localhost:5000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "owner@example.com",
"password": "Passw0rd!"
}'- Copy JWT token from response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": { ... }
}- Use this JWT token in Authorization header:
# Replace YOUR_TOKEN_HERE with the actual JWT token from login response
curl -X POST http://localhost:5000/api/auth/seed-admins \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{"admins": [...]}'Important Notes:
YOUR_TOKEN_HERE= JWT token from login response (starts with eyJhbGciOiJIUzI1NiI...)- NOT the
ADMIN_SEED_TOKENfrom.envfile - The
.envtoken is only for CLI seeding, not API authentication
- Initial Setup: Use CLI method for the first admin
- Easy Admin Creation: Use REST Client method (Method 2) for non-technical users
- Additional Admins: Use API method for subsequent admins
- Batch Creation: Use multiple admin seeding for bulk operations
- Secure Passwords: Always use strong, unique passwords
- Environment Variables: Keep sensitive data in
.envfiles - Token Security: Never share or expose admin tokens
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "REST Client"
- Install the extension by Huachao Mao
- Open
api/seedAdmin.restfile - You'll see "Send Request" links above each HTTP request
After seeding, test the admin accounts:
-
Using REST Client (Easiest):
- Open
api/seedAdmin.rest - Use the "Test new admin login" request
- Update email/password and click "Send Request"
- Open
-
Using curl:
curl -X POST http://localhost:5000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "YOUR_ADMIN_EMAIL",
"password": "YOUR_ADMIN_PASSWORD"
}'- Access Admin Panel:
- Navigate to:
http://localhost:5173/owner/login - Login with seeded credentials
- Verify admin dashboard access
- Navigate to: