SDK
SDK Javascript v6.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

createFirstAdmin #

Creates a Kuzzle administrator account, only if none exist.


createFirstAdmin(kuid, body, [options]);

PropertyTypeDescription
kuid
string
Administrator kuid
body
object
Administrator content & credentials
options
object
Query options

body #

The body property must contain two objects:

  • content: Administrator additional information. Can be left empty. Any other attribute can be added. Make sure to update the user mapping collection to match your custom attributes.
  • credentials: Describe how the new administrator can be authenticated. This object must contain one or more properties, named after the target authentication strategy to use. Each one of these properties are objects containing the credentials information, corresponding to that authentication strategy.

Example:

{
  content: {
    firstName: 'John',
    lastName: 'Doe'
  },
  credentials: {
    local: {
      username: 'admin',
      password: 'myPassword'
    }
  }
}

options #

PropertyType
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
reset
boolean

(false)
If true, restricted permissions are applied to anonymous and default roles

Resolves #

A User object containing information about the newly created administrator.

Usage #

try {
  const response = await kuzzle.security.createFirstAdmin(
    'admin',
    {
      content: {
        firstName: 'John',
        lastName: 'Doe'
      },
      credentials: {
        local: {
          username: 'admin',
          password: 'myPassword'
        }
      }
    }
  );
  console.log(response);
  /*
  User {
    _id: 'admin',
    content:
      { profileIds: [ 'admin' ],
        firstName: 'John',
        lastName: 'Doe',
        _kuzzle_info:
          { author: '-1',
            createdAt: 1560351009496,
            updatedAt: null,
            updater: null  } } }
   */
  console.log('First admin successfully created');
} catch (e) {
  console.error(e);
}