UNPKG

codalware-auth

Version:

Complete authentication system with enterprise security, attack protection, team workspaces, waitlist, billing, UI components, 2FA, and account recovery - production-ready in 5 minutes. Enhanced CLI with verification, rollback, and App Router scaffolding.

117 lines (98 loc) 3.02 kB
/* eslint-disable */ let nodemailer = null; try { nodemailer = require('nodemailer'); } catch { nodemailer = null; } const { EMAIL_SERVER_HOST, EMAIL_SERVER_PORT, EMAIL_SERVER_USER, EMAIL_SERVER_PASSWORD, GMAIL_ACCOUNT_EMAIL, GOOGLE_PASS, env, } = require('./env.js'); let cachedTransporter = null; let initializationAttempted = false; const buildTransporter = () => { if (!nodemailer) { console.warn('⚠️ nodemailer is not installed. Install it to enable email sending or provide a custom transporter.'); return null; } const emailService = env.EMAIL_SERVICE; if (emailService) { const serviceUser = GMAIL_ACCOUNT_EMAIL || EMAIL_SERVER_USER; const servicePass = GOOGLE_PASS || EMAIL_SERVER_PASSWORD; if (!serviceUser || !servicePass) { console.warn('⚠️ EMAIL_SERVICE is set but credentials are missing. Provide GMAIL_ACCOUNT_EMAIL & GOOGLE_PASS or EMAIL_SERVER_USER & EMAIL_SERVER_PASSWORD'); return null; } console.log(`✉️ Using ${emailService} service for email`); return nodemailer.createTransport({ service: emailService, auth: { user: serviceUser, pass: servicePass, }, }); } if (EMAIL_SERVER_HOST && EMAIL_SERVER_PORT) { const port = parseInt(EMAIL_SERVER_PORT, 10) || 587; console.log(`✉️ Using SMTP: ${EMAIL_SERVER_HOST}:${port}`); return nodemailer.createTransport({ host: EMAIL_SERVER_HOST, port, secure: port === 465, auth: EMAIL_SERVER_USER ? { user: EMAIL_SERVER_USER, pass: EMAIL_SERVER_PASSWORD, } : undefined, }); } if (GMAIL_ACCOUNT_EMAIL && GOOGLE_PASS) { console.log('✉️ Using Gmail (legacy configuration)'); return nodemailer.createTransport({ service: 'gmail', auth: { user: GMAIL_ACCOUNT_EMAIL, pass: GOOGLE_PASS, }, }); } console.warn('⚠️ No email configuration found. Email sending will not work.'); return null; }; const ensureTransporter = () => { if (cachedTransporter || initializationAttempted) { return cachedTransporter; } initializationAttempted = true; cachedTransporter = buildTransporter(); return cachedTransporter; }; const lazyTransporter = new Proxy({}, { get: (_target, prop) => { if (prop === '__esModule') { return true; } if (prop === 'default') { return ensureTransporter(); } if (prop === Symbol.toStringTag) { return 'AuthCoreLazyTransporter'; } const instance = ensureTransporter(); if (!instance) { return undefined; } const value = instance[prop]; return typeof value === 'function' ? value.bind(instance) : value; }, }); module.exports = lazyTransporter; module.exports.createTransporter = buildTransporter; module.exports.ensureTransporter = ensureTransporter;