Users

User provide a finley tuned way to capture specific data about the status of a user in your application. This can be used to track user activity, monitor connection status, and subscribe to update events.


The User Object

To create a subscription to a user you need to make a call to auth.getUser() passing the clientId of the user you want to subscribe to.

const user = await relayBox.auth.getUser({
  clientId: '1234abcde'
});
OptionsDescriptionType
clientIdUser clientId: The clientId of the user to be retrieved.string

A sucessful response will return a user object in the following format.

{
  "id": "12345678-1234-1234-1234-123456789012",
  "clientId": "5nlyz4cYLqZD",
  "createdAt": "2024-09-11T07:27:12.151Z",
  "updatedAt": "2024-09-11T07:27:12.151Z",
  "username": "ShinyKrill709",
  "orgId": "12345678-1234-1234-1234-123456789012",
  "appId": "12345678-1234-1234-1234-123456789012",
  "isOnline": true,
  "lastOnline": "2024-09-13T20:40:52.917Z",
  "blockedAt": null
}

Once a user has been created you have the ability to listen to connection and status events using the methods described throughout the rest of this section.


user.onConnectionEvent()

Capture all connection events for given user

user.onConnectionEvent((user) => {
  console.log(user);
});

Example:

const user = await relayBox.auth.getUser({
  clientId: '1234abcde'
});

user.onConnectionEvent((user) => {
  console.log(user);
});

user.onConnect()

Capture connect events for given user

user.onConnect((user) => {
  console.log(user);
});

Example:

const user = await relayBox.auth.getUser({
  clientId: '1234abcde'
});

user.onConnect((user) => {
  console.log(user);
});

user.onDisconnect()

Capture disconnect events for given user

user.onDisconnect((user) => {
  console.log(user);
});

Example:

const user = await relayBox.auth.getUser({
  clientId: '1234abcde'
});

user.onDisconnect((user) => {
  console.log(user);
});

user.onStatusUpdate()

Capture status update events for given user. Status updates can contain any data structure from simple strings to complex objects.

user.onDisconnect(({ status, updatedAt, user }) => {
  console.log(status, user);
  console.log(status, user);
});

Example:

const user = await relayBox.auth.getUser({
  clientId: '1234abcde'
});

user.onStatusUpdate(({ status, updatedAt, user }) => {
  console.log(status, updatedAt, user);
});

    On this page