@dax-crafta/auth 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/email.js +50 -0
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const nodemailer = require('nodemailer');
|
|
2
|
+
|
|
3
|
+
class EmailService {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.transporter = nodemailer.createTransport(config.smtp);
|
|
6
|
+
this.from = config.smtp.from;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async sendVerificationEmail(user, token) {
|
|
10
|
+
const verificationUrl = `${this.config.baseUrl}/verify-email?token=${token}`;
|
|
11
|
+
|
|
12
|
+
await this.transporter.sendMail({
|
|
13
|
+
from: this.from,
|
|
14
|
+
to: user.email,
|
|
15
|
+
subject: 'Verify Your Email',
|
|
16
|
+
html: `Click here to verify your email: <a href="${verificationUrl}">${verificationUrl}</a>`
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async sendPasswordResetEmail(user, token) {
|
|
21
|
+
const resetUrl = `${this.config.baseUrl}/reset-password?token=${token}`;
|
|
22
|
+
|
|
23
|
+
await this.transporter.sendMail({
|
|
24
|
+
from: this.from,
|
|
25
|
+
to: user.email,
|
|
26
|
+
subject: 'Reset Your Password',
|
|
27
|
+
html: `Click here to reset your password: <a href="${resetUrl}">${resetUrl}</a>`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async sendLoginAlert(user, deviceInfo) {
|
|
32
|
+
await this.transporter.sendMail({
|
|
33
|
+
from: this.from,
|
|
34
|
+
to: user.email,
|
|
35
|
+
subject: 'New Login Detected',
|
|
36
|
+
html: `New login detected from ${deviceInfo.browser} on ${deviceInfo.os}`
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async send2FACode(user, code) {
|
|
41
|
+
await this.transporter.sendMail({
|
|
42
|
+
from: this.from,
|
|
43
|
+
to: user.email,
|
|
44
|
+
subject: '2FA Code',
|
|
45
|
+
html: `Your 2FA code is: ${code}`
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = EmailService;
|