UNPKG

@dax-crafta/auth

Version:

A powerful, flexible, and secure authentication plugin for the Crafta framework. Supports JWT, social login, 2FA, RBAC, audit logging, and enterprise-grade security features.

50 lines (42 loc) 1.44 kB
const nodemailer = require('nodemailer'); class EmailService { constructor(config) { this.transporter = nodemailer.createTransport(config.smtp); this.from = config.smtp.from; } async sendVerificationEmail(user, token) { const verificationUrl = `${this.config.baseUrl}/verify-email?token=${token}`; await this.transporter.sendMail({ from: this.from, to: user.email, subject: 'Verify Your Email', html: `Click here to verify your email: <a href="${verificationUrl}">${verificationUrl}</a>` }); } async sendPasswordResetEmail(user, token) { const resetUrl = `${this.config.baseUrl}/reset-password?token=${token}`; await this.transporter.sendMail({ from: this.from, to: user.email, subject: 'Reset Your Password', html: `Click here to reset your password: <a href="${resetUrl}">${resetUrl}</a>` }); } async sendLoginAlert(user, deviceInfo) { await this.transporter.sendMail({ from: this.from, to: user.email, subject: 'New Login Detected', html: `New login detected from ${deviceInfo.browser} on ${deviceInfo.os}` }); } async send2FACode(user, code) { await this.transporter.sendMail({ from: this.from, to: user.email, subject: '2FA Code', html: `Your 2FA code is: ${code}` }); } } module.exports = EmailService;