Awesome, thanks for helping with that.
I have one more related question tho. What about bootstrapping super admin?
I tried using this script:
const createSuperAdminUser = async () => {
const params = {
username: process.env.ADMIN_USER,
password: process.env.ADMIN_PASS,
firstname: process.env.ADMIN_USER,
lastname: process.env.ADMIN_USER,
email: process.env.ADMIN_EMAIL,
blocked: false,
isActive: true,
}
const admins = await strapi.query('user', 'admin').find({ _limit: 1 })
if (admins.length) {
console.error(`Admin user already exists: ${admins[0].email}`)
return
}
try {
// in the admin under services you can find the super admin role
const superAdminRole = await strapi.admin.services.role.getSuperAdmin()
// Hash password before storing in the database
params.roles = [superAdminRole.id]
params.password = await strapi.admin.services.auth.hashPassword(params.password)
// Create admin account
const admin = await strapi.query('user', 'admin').create({...params})
console.info('Admin account created:', admin)
} catch (error) {
console.error(error)
}
}
But when it gets to
params.roles = [superAdminRole.id]
It fails with:
app | TypeError: Cannot read property 'id' of null
app | at createSuperAdminUser (/srv/app/config/functions/bootstrap.js:35:36)
app | at async module.exports (/srv/app/config/functions/bootstrap.js:83:5)
app | at async Strapi.runBootstrapFunctions (/srv/app/node_modules/strapi/lib/Strapi.js:407:5)
app | at async Strapi.load (/srv/app/node_modules/strapi/lib/Strapi.js:336:5)
app | at async Strapi.start (/srv/app/node_modules/strapi/lib/Strapi.js:190:9)
Because:
const superAdminRole = await strapi.admin.services.role.getSuperAdmin()
Returns null at first startup. Is that normal?