Nimbu Developer Docs

Customers & Sessions

Manage Nimbu customer accounts, current sessions, and password resets with the JS SDK.

Nimbu.Customer represents customer accounts. It extends Nimbu.Object.

Create A Customer

const customer = new Nimbu.Customer({
  email: '[email protected]',
  firstname: 'Ada',
  lastname: 'Lovelace'
});

await customer.save();

Sign Up

const customer = await Nimbu.Customer.signUp('[email protected]', 'secret', {
  email: '[email protected]',
  firstname: 'Ada',
  lastname: 'Lovelace'
});

Successful signup makes the customer current.

Log In

try {
  const customer = await Nimbu.Customer.logIn('[email protected]', 'secret');
  console.log(customer.id);
} catch (error) {
  console.error(error.message);
}

Successful login stores the current customer session.

Current Customer

const current = Nimbu.Customer.current();

if (current && current.authenticated()) {
  console.log(current.get('email'));
}

Initialize the SDK before reading the current customer in browser or external usage:

await Nimbu.initialize(accessToken);
const current = Nimbu.Customer.current();

Become A Customer Session

Use become() when you already have a customer session token.

const customer = await Nimbu.Customer.become(sessionToken, {
  useACL: true
});

Log Out

await Nimbu.Customer.logOut();

This clears the current customer from SDK storage.

Password Reset

await Nimbu.Customer.requestPasswordReset('[email protected]', {
  useACL: true
});

Customer Queries

const customer = await new Nimbu.Query(Nimbu.Customer)
  .equalTo('email', '[email protected]')
  .first();

You can query customers as a string too, but the class form returns Nimbu.Customer instances.

Roles

const customer = await new Nimbu.Query(Nimbu.Customer).get(customerId);
const role = await new Nimbu.Query(Nimbu.Role).get(roleId);

role.getCustomers().add(customer);
await role.save();

On this page