Navigation

Listen to events

The Sabil JavaScript SDK exposes three events:

Each of these function can be passed as a named parameter to the attach call.

await Sabil.attach({  client_id: `client_id`,  user: `user_id`,  on_limit_exceeded: ({ attached_devices }) => {    console.log(attached_devices);  },  on_current_device_logout: () => {    //TODO: [important] Perform log out logic  },  on_other_device_logout: (device) => {    console.log(device);  },});

on_limit_exceeded

This is called when the user exceeds the specified device limit. For details on limits, see the Configuring device limits guide. A single parameter is passed to this function: an object containing the device count attached_devices

on_current_device_logout

This function is called whenever the current device needs to be detached. This can happen in one of two scenarios:

  1. The user was shown the dialog and select to log out of this device. Keep in mind, the user could be asking to log out this device from another device where the dialog is presented.
  2. You manually call detach and passed the device ID of a specific device. If the device with that ID implements this callback and it's online, it will be immediately called.

It is strongly recommended that you implement this callback. Inside this callback, you should immediately log the user out of your application.

on_other_device_logout

This is called if and only if the user is shown the blocking dialog, and selects to log out another device. This function takes one parameter which is the device details that was selected to log out. You should avoid calling detach here because it will already be invoked by the SDK. Use this only for your internal purposes and nothing else. It is perfectly safe to ignore this callback.