fix: use LOGIN auth method for SMTP (mailcow compatibility)
This commit is contained in:
@@ -7,6 +7,7 @@ import { JwtService } from '@nestjs/jwt';
|
|||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { PrismaService } from '../prisma/prisma.service';
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
|
import * as nodemailer from 'nodemailer';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
@@ -29,8 +30,46 @@ export class AuthService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: integrate real email service (SMTP, SendGrid, etc.)
|
const smtpHost = this.config.get<string>('SMTP_HOST');
|
||||||
|
const smtpPort = this.config.get<number>('SMTP_PORT', 587);
|
||||||
|
const smtpUser = this.config.get<string>('SMTP_USER');
|
||||||
|
const smtpPass = this.config.get<string>('SMTP_PASS');
|
||||||
|
const mailFrom = this.config.get<string>(
|
||||||
|
'MAIL_FROM',
|
||||||
|
'radiOLA <noreply@nexaweb.su>',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (smtpHost && smtpUser && smtpPass) {
|
||||||
|
try {
|
||||||
|
const transporter = nodemailer.createTransport({
|
||||||
|
host: smtpHost,
|
||||||
|
port: smtpPort,
|
||||||
|
secure: smtpPort === 465,
|
||||||
|
auth: {
|
||||||
|
user: smtpUser,
|
||||||
|
pass: smtpPass,
|
||||||
|
},
|
||||||
|
authMethod: 'LOGIN',
|
||||||
|
tls: {
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await transporter.sendMail({
|
||||||
|
from: mailFrom,
|
||||||
|
to: email,
|
||||||
|
subject: 'Ваш код подтверждения radiOLA',
|
||||||
|
text: `Ваш код подтверждения: ${code}\n\nКод действителен 15 минут.`,
|
||||||
|
html: `<p>Ваш код подтверждения: <strong>${code}</strong></p><p>Код действителен 15 минут.</p>`,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to send email:', error.message);
|
||||||
|
// Fallback to console log for debugging
|
||||||
console.log(`Magic link code for ${email}: ${code}`);
|
console.log(`Magic link code for ${email}: ${code}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`Magic link code for ${email}: ${code}`);
|
||||||
|
}
|
||||||
|
|
||||||
return { message: 'Check your email for the verification code.' };
|
return { message: 'Check your email for the verification code.' };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user