Templates

The Express Server library uses the SDK's Notifier module for sending Email and SMS for OTP verifications. The library includes default templates (handlebar files) but can be overridden by your own templates.

The Email template may be found in src/templates/otp/email.handlebars.

The exposed data are as follows:

ParameterDescription
vars.brandFilled with the data from config -> OTP Settings.
data.codeThe generated OTP code that will be delivered to the user.

The SMS template may be found in src/templates/otp/sms.handlebars.

The exposed data are as follows:

ParameterDescription
vars.brandFilled with the data from config -> OTP Settings.
data.codeThe generated OTP code that will be delivered to the user.

In order to replace templates with your own customized templates, use the following code snippet (taken from Notifications docs) to declare the templates first:

import { Notifications } from "@ssofy/node-sdk";
...
const templates = [
    <Notifications.Template>{
        name: 'otp',
        path: 'PATH_TO_SMS_HANDLEBARS_TEMPLATE_FILE',
        engine: Notifications.HandlebarsEngine,
        channel: Notifications.Channel.SMS
    },
    <Notifications.Template>{
        name: 'otp',
        path: 'PATH_TO_EMAIL_HANDLEBARS_TEMPLATE_FILE',
        engine: Notifications.HandlebarsEngine,
        channel: Notifications.Channel.EMAIL
    },
];

And then, pass the templates object to the notifiers:

const serverConfig: ServerConfig = {
    ...
    otp: {
        storage: new Storage.MemoryStorage(),
        vars: {
            brand: 'SSOfy',
        },
        notifiers: [
            new Notifications.ConsoleNotifier(Notifications.Channel.SMS, 'Test', templates),
            new Notifications.ConsoleNotifier(Notifications.Channel.EMAIL, 'Test', templates),
        ],
    },
    ...
};
ssofyKnowledge 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.