SDK
SDK Javascript v7.x
2

createFirstAdmin #

Creates a Kuzzle administrator account, only if none exist.


Copied to clipboard!
createFirstAdmin(kuid, body, [options]);

Property Type Description
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:

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

options #

Property Type
(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 #

Copied to clipboard!
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);
}