Skip to content

Subscribe to events

  • managementClient.sub(eventCode,callback,errCallback)

    Use WebSocket to subscribe to events generated by authing. eventCode is the event code. You can view available events in GenAuth API Explorer .

Parameters

  • eventCode <String> event code
  • callback <Function> custom receiver
  • errCallback <Function> custom error receiver

Example

javascript
import { ManagementClient } from "authing-node-sdk";

const managementClient = new ManagementClient({
  accessKeyId: "ACCESS_KEY_ID",
  accessKeySecret: "ACCESS_KEY_SECRET",
  retryTimes: 0, // socket connection failure retry times
});

managementClient.sub(
  "authing.user.created",
  (msg: string) => {
    console.log(msg);
  },
  (err) => {
    console.log(err);
  }
);

Publish events

  • managementClient.pub(eventCode, data)

Parameters

  • eventCode <String> event code
  • data <String> event body

Example

javascript
managementClient.pub(
  "CUSTOM_EVENT",
  JSON.stringify({
    email: "test@example.com",
    phone: "188xxxx8888",
    name: "xxxx",
    customData: {
      school: "pku",
      age: 22,
    },
  })
);

Agent infrastructure for identity, memory, and web action.