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.

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
strategy
string
Name of the strategy to use
credentials
object
Credentials for the strategy
expiresIn
string
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);
  console.log(jwt);
  /*
    'eyJhbGciOiJIUzI1NiIsIkpXVCJ9.eyJfaWQiOiJmb28iLCJpYXQiOjE.wSPmb0z2tErRdYEg'
  */
  console.log('Success');
} catch (error) {
  console.error(error.message);
}