@krypton-org/krypton-auth
Version:
Express authentication middleware, using GraphQL and JSON Web Tokens.
50 lines • 2.53 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const nodemailer_1 = __importDefault(require("nodemailer"));
const config_1 = __importDefault(require("../config"));
const Mailer_1 = __importDefault(require("../mailer/Mailer"));
/**
* Define job type of sending an email in the Agenda process queue.
* @param {Agenda} agenda
* @returns {void}
*/
function default_1(agenda) {
agenda.define('email', (job) => __awaiter(this, void 0, void 0, function* () {
try {
const info = yield Mailer_1.default(job.attrs.data);
if (!config_1.default.nodemailerConfig) {
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer_1.default.getTestMessageUrl(info));
const clientId = job.attrs.data.clientId;
if (clientId && config_1.default.clientIdToSocket.has(clientId)) {
config_1.default.clientIdToSocket.get(clientId).emit('notification', {
message: 'To open the preview click <a style="color: #007bff; text-decoration: none; background-color: transparent;" href="' +
nodemailer_1.default.getTestMessageUrl(info) +
'" target="_blank"/>here</a>.',
title: 'Mock email sent.',
type: 'info',
});
}
}
}
catch (err) {
if (config_1.default.eventEmitter) {
config_1.default.eventEmitter.emit('email-error', job.attrs.data);
}
}
}));
}
exports.default = default_1;
//# sourceMappingURL=email.js.map