UNPKG

@bitwild/rockets-auth

Version:

Rockets Auth - Complete authentication and authorization solution for NestJS with JWT, OAuth, OTP, role-based access control, and more

64 lines 3.43 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var RocketsAuthNotificationService_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.RocketsAuthNotificationService = void 0; const common_1 = require("@nestjs/common"); const nestjs_common_1 = require("@concepta/nestjs-common"); const nestjs_email_1 = require("@concepta/nestjs-email"); const rockets_auth_constants_1 = require("../../../shared/constants/rockets-auth.constants"); const rockets_auth_exception_1 = require("../../../shared/exceptions/rockets-auth.exception"); const error_logging_helper_1 = require("../../../shared/utils/error-logging.helper"); let RocketsAuthNotificationService = RocketsAuthNotificationService_1 = class RocketsAuthNotificationService { constructor(settings, emailService) { this.settings = settings; this.emailService = emailService; this.logger = new common_1.Logger(RocketsAuthNotificationService_1.name); } async sendOtpEmail(params) { const { email, passcode } = params; try { const { fileName, subject } = this.settings.email.templates.sendOtp; const { from, baseUrl } = this.settings.email; await this.emailService.sendMail({ to: email, from, subject, template: fileName, context: { passcode, tokenUrl: `${baseUrl}/${passcode}`, }, }); this.logger.log('OTP email sent successfully'); } catch (error) { const { errorMessage } = (0, error_logging_helper_1.logAndGetErrorDetails)(error, this.logger, 'Failed to send OTP email', { errorId: 'OTP_EMAIL_SEND_FAILED' }); if (error instanceof nestjs_common_1.RuntimeException) { throw error; } else { throw new rockets_auth_exception_1.RocketsAuthException(errorMessage); } } } }; exports.RocketsAuthNotificationService = RocketsAuthNotificationService; exports.RocketsAuthNotificationService = RocketsAuthNotificationService = RocketsAuthNotificationService_1 = __decorate([ (0, common_1.Injectable)(), __param(0, (0, common_1.Inject)(rockets_auth_constants_1.ROCKETS_AUTH_MODULE_OPTIONS_DEFAULT_SETTINGS_TOKEN)), __param(1, (0, common_1.Inject)(nestjs_email_1.EmailService)), __metadata("design:paramtypes", [Object, Object]) ], RocketsAuthNotificationService); //# sourceMappingURL=rockets-auth-notification.service.js.map