Inspired by wasaluduckworth/add-admin-user-programmatically-in-ghost I have created a tool for adding users manually without the need for invite with mail.
-
Create as js-file “users.js” in the root-directory of your ghost website
-
users.js
require('./current/core/server/models/role');
const UserModel = require('./current/core/server/models/user');
const {Command} = require('./current/node_modules/commander');
const program = new Command();
program.command('add')
.description('Add a new user')
.option('--name <name>', 'Name')
.option('--email <email>', 'Email')
.option('--password <password>', 'Password')
.option('--role <role>', 'Role','Editor')
.action(async (options) => {
const {email, name, password, role} = options;
try {
await UserModel.User.add(
{
email,
name,
password,
roles: [role],
},
{}
);
console.log('User added successfully.');
} catch (err) {
console.error('Error adding user:', err);
}
process.exit();
});
program.parse(process.argv);
- Execute
node users.js add --email editor@domain.com --name John --password atleast10chars
You can add a --role too:
Role can be Administrator || Editor || Author || Contributor
Default: Editor