Skip to main content

SMS Templates Configuration

Package: @nauth-toolkit/core Type: Configuration

Configure custom SMS templates and global variables for branding.

import { AuthModule } from '@nauth-toolkit/nestjs';

AuthModule.forRoot({
sms: {
templates: {
globalVariables: {
appName: 'My App',
supportPhone: '+1-800-123-4567',
},
customTemplates: {
verification: {
content: '{{appName}}: Your code is {{code}}. Expires in {{expiryMinutes}} min.',
},
},
},
},
});

Properties

PropertyTypeRequiredDescription
engineSMSTemplateEngineNoCustom template engine instance (default: SMSTemplateEngineImpl)
globalVariablesRecord<string, string | number | boolean | undefined>NoGlobal variables available to all templates
customTemplatesRecord<string, CustomSMSTemplateDefinition>NoCustom template definitions (override defaults)

Global Variables

Global variables are merged with template-specific variables at render time. Template-specific variables take precedence.

Common global variables:

  • appName - Your application name
  • companyName - Your company name
  • supportPhone - Support contact phone number

Custom Templates

Custom templates can be provided as inline content or file paths:

Inline Content

customTemplates: {
verification: {
content: '{{appName}}: Your verification code is {{code}}. Valid for {{expiryMinutes}} minutes.',
},
}

File Path

customTemplates: {
verification: {
contentPath: './sms-templates/verification.txt.hbs',
},
}

Template Types

TypeRequired VariablesDescription
verification{{code}}, {{expiryMinutes}}Phone verification codes
mfa{{code}}, {{expiryMinutes}}Multi-factor authentication
passwordReset{{code}}, {{expiryMinutes}}Password reset codes

Examples

Basic Configuration

sms: {
templates: {
globalVariables: {
appName: process.env.APP_NAME || 'My Application',
companyName: 'My Company Inc.',
supportPhone: '+1-800-123-4567',
},
},
}

Custom Templates

sms: {
templates: {
globalVariables: {
appName: 'My App',
},
customTemplates: {
verification: {
content: '{{appName}}: Your code is {{code}}. Expires in {{expiryMinutes}} min.',
},
mfa: {
contentPath: './sms-templates/mfa.txt.hbs',
},
},
},
}

Mixed Configuration

sms: {
templates: {
globalVariables: {
appName: 'My App',
companyName: 'My Company',
},
customTemplates: {
verification: {
content: '{{appName}}: Code {{code}} expires in {{expiryMinutes}} min.',
},
passwordReset: {
contentPath: './sms-templates/password-reset.txt.hbs',
},
},
},
}