62 lines
2.2 KiB
Markdown
62 lines
2.2 KiB
Markdown
The seed script skips creation if the email already exists. The
|
|
most flexible approach is a direct API call (if you have a token)
|
|
or a one-liner script. Here are both options:
|
|
|
|
Option 1 — via API (requires an existing admin to be logged in
|
|
first):
|
|
|
|
curl -s -X POST http://localhost:4000/api/v1/admin/admins \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: Bearer <your_admin_token>" \
|
|
-d '{
|
|
"email": "newadmin@example.com",
|
|
"firstName": "First",
|
|
"lastName": "Last",
|
|
"role": "ADMIN",
|
|
"password": "yourpassword123"
|
|
}'
|
|
|
|
Option 2 — directly in the database (no token needed, works any
|
|
time):
|
|
|
|
DATABASE_URL="postgresql://postgres:password@localhost:5432/renta
|
|
ldrivego" node -e "
|
|
const { PrismaClient } =
|
|
require('./packages/database/generated');
|
|
const bcrypt = require('./node_modules/bcryptjs');
|
|
const p = new PrismaClient();
|
|
const EMAIL = 'newadmin@example.com';
|
|
const PASSWORD = 'yourpassword123';
|
|
const FIRST = 'First';
|
|
const LAST = 'Last';
|
|
const ROLE = 'SUPER_ADMIN'; // SUPER_ADMIN | ADMIN | SUPPORT |
|
|
FINANCE | VIEWER
|
|
bcrypt.hash(PASSWORD, 12).then(hash =>
|
|
p.adminUser.create({ data: { email: EMAIL, firstName: FIRST,
|
|
lastName: LAST, passwordHash: hash, role: ROLE, isActive: true }
|
|
})
|
|
).then(a => { console.log('Created:', a.email, a.role);
|
|
p.\$disconnect(); })
|
|
.catch(e => { console.error('Error:', e.message);
|
|
p.\$disconnect(); });
|
|
"
|
|
|
|
From inside Docker:
|
|
|
|
docker exec rentaldrivego-dev-api-1 node -e "
|
|
const { PrismaClient } =
|
|
require('/app/packages/database/generated');
|
|
const bcrypt = require('/app/node_modules/bcryptjs');
|
|
const p = new PrismaClient();
|
|
bcrypt.hash('yourpassword123', 12).then(hash =>
|
|
p.adminUser.create({ data: { email: 'newadmin@example.com',
|
|
firstName: 'First', lastName: 'Last', passwordHash: hash, role:
|
|
'SUPER_ADMIN', isActive: true } })
|
|
).then(a => { console.log('Created:', a.email, a.role);
|
|
p.\$disconnect(); })
|
|
.catch(e => { console.error('Error:', e.message);
|
|
p.\$disconnect(); });
|
|
"
|
|
|
|
Replace email, password, firstName, lastName, and role as needed.
|
|
Available roles: SUPER_ADMIN, ADMIN, SUPPORT, FINANCE, VIEWER. |