Events

SDK comes with wrappers around different node modules for sending event through different channels in a single interface named Channel.

The SDK currently supports the following channels:

  • NodeEventChannel (Built-in Node.js EventEmitter)
  • RedisEventChannel (redis)
import { Events } from "@ssofy/node-sdk";
...
const eventChannel = new Events.NodeEventChannel({
    // EventEmitter options
});

eventChannel.subscribe('my-event', (event: string, message?: any) => {
    console.log(`{[Event] ${event}:`, message);
});

eventChannel.publish('my-event', {
    message: 'test',
});

Installing dependencies:

    npm i redis -S
import { Events } from "@ssofy/node-sdk";
import { createClient } from 'redis';
...
const client = createClient();
client.connect();

const eventChannel = new Events.RedisEventChannel(
    client, // publisher client
    client, // subscriber client
    'sso:', // prefix
);

eventChannel.subscribe('my-event', (event: string, message?: any) => {
    console.log(`{[Event] ${event}:`, message);
});

eventChannel.publish('my-event', {
    message: 'test',
});

You may also build your own custom event channel by implementing the Channel Interface.

ssofy Knowledge Base
At our core, we believe that staying up-to-date with the latest trends and advancements in Authentication and related areas is essential. That's why we take great pride in keeping you informed with the latest insights, updates, and news in this rapidly evolving landscape.


Do you need support?
SSOfy is by Cubelet Ltd.
Copyright © 2024 Cubelet Ltd. All rights reserved.