SDK Javascript v6.x

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.

login #

Authenticates a user.

If this action is successful, then the jwt property of this class instance is set to the new authentication token.

All further requests emitted by this SDK instance will be on behalf of the authenticated user, until either the authenticated token expires, the logout action is called, or the jwt property is manually set to another value.

Arguments #

Copied to clipboard!
login(strategy, [credentials], [expiresIn]);

Arguments Type Description
Name of the strategy to use
Credentials for the strategy
Expiration time in ms library format. (e.g. 2h)

strategy #

The name of the authentication strategy used to log the user in.

Depending on the chosen authentication strategy, additional credential arguments may be required. The API request example in this page provides the necessary arguments for the local authentication plugin.

Check the appropriate authentication plugin documentation to get the list of additional arguments to provide.

expiresIn #

The default value for the expiresIn option is defined at server level, in Kuzzle's configuration file.

Resolves #

The login action returns the encrypted JSON Web Token.

Usage #

Local strategy login example

Copied to clipboard!
const credentials = { username: 'foo', password: 'bar' };
try {
  const jwt = await kuzzle.auth.login('local', credentials);
} catch (error) {