auth-verify 1.11.0 → 1.11.1
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/readme.md +1 -0
- package/rest-api/index.js +46 -21
- package/src/otp/index.js +1 -1
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"uuid": "^9.0.1"
|
|
16
16
|
},
|
|
17
17
|
"name": "auth-verify",
|
|
18
|
-
"version": "1.11.
|
|
18
|
+
"version": "1.11.1",
|
|
19
19
|
"description": "A simple Node.js library for sending and verifying OTP via email, SMS and Telegram bot. And generating TOTP codes and QR codes. And handling JWT with Cookies. And also handling passwordless logins with passkeys/webauth. And handling magiclink passwordless logins",
|
|
20
20
|
"main": "index.js",
|
|
21
21
|
"scripts": {
|
package/readme.md
CHANGED
package/rest-api/index.js
CHANGED
|
@@ -72,43 +72,68 @@ router.post('/auth/otp/send/gmail/:to', async (req, res) => {
|
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
// -----------
|
|
76
|
-
router.post('/auth/otp/send/email/:to', async (req, res) => {
|
|
75
|
+
// ----------- Brevo Provider -------------
|
|
76
|
+
router.post('/auth/otp/send/email/brevo/:to', async (req, res) => {
|
|
77
77
|
try {
|
|
78
78
|
const { to } = req.params;
|
|
79
|
-
const {
|
|
79
|
+
const { name, email, subject, text, html, apikey } = req.body.sender || {};
|
|
80
80
|
|
|
81
|
-
if (!email || !
|
|
82
|
-
return res.status(400).json({ error: "Missing
|
|
81
|
+
if (!email || !apikey) {
|
|
82
|
+
return res.status(400).json({ error: "Missing email or Brevo API key" });
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
auth.otp.
|
|
86
|
-
via: 'email',
|
|
87
|
-
host,
|
|
88
|
-
port,
|
|
89
|
-
secure: secure || false,
|
|
90
|
-
sender: email,
|
|
91
|
-
pass
|
|
92
|
-
});
|
|
85
|
+
const otp = auth.otp.generate(6);
|
|
93
86
|
|
|
94
|
-
const
|
|
87
|
+
const payload = {
|
|
88
|
+
sender: { name: name || "AuthVerify", email },
|
|
89
|
+
to: [{ email: to }],
|
|
95
90
|
subject: subject || "Your OTP Code",
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
91
|
+
htmlContent: html || `<b>Your OTP code is: ${otp.code}</b>`,
|
|
92
|
+
textContent: text || `Your OTP code is: ${otp.code}`
|
|
93
|
+
};
|
|
99
94
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
provider: "smtp",
|
|
103
|
-
to
|
|
95
|
+
const response = await axios.post("https://api.brevo.com/v3/smtp/email", payload, {
|
|
96
|
+
headers: { "api-key": apikey, "Content-Type": "application/json" }
|
|
104
97
|
});
|
|
105
98
|
|
|
99
|
+
return res.json({ ok: true, provider: "brevo", to, code: otp.code, providerData: response.data });
|
|
106
100
|
} catch (err) {
|
|
107
101
|
console.error(err);
|
|
108
102
|
return res.status(500).json({ error: "Failed to send OTP" });
|
|
109
103
|
}
|
|
110
104
|
});
|
|
111
105
|
|
|
106
|
+
router.post('/auth/otp/send/email/sendgrid/:to', async (req, res) => {
|
|
107
|
+
try {
|
|
108
|
+
const { to } = req.params;
|
|
109
|
+
const { apikey, subject, text, html } = req.body.sender || {};
|
|
110
|
+
|
|
111
|
+
if (!apikey) return res.status(400).json({ error: "Missing SendGrid API key" });
|
|
112
|
+
|
|
113
|
+
const otp = auth.otp.generate(6);
|
|
114
|
+
|
|
115
|
+
const payload = {
|
|
116
|
+
personalizations: [{ to: [{ email: to }] }],
|
|
117
|
+
from: { email: "no-reply@yourdomain.com", name: "AuthVerify" },
|
|
118
|
+
subject: subject || "Your OTP Code",
|
|
119
|
+
content: [
|
|
120
|
+
{ type: "text/plain", value: text || `Your OTP code is: ${otp.code}` },
|
|
121
|
+
{ type: "text/html", value: html || `<b>Your OTP code is: ${otp.code}</b>` }
|
|
122
|
+
]
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const response = await axios.post("https://api.sendgrid.com/v3/mail/send", payload, {
|
|
126
|
+
headers: { "Authorization": `Bearer ${apikey}`, "Content-Type": "application/json" }
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return res.json({ ok: true, provider: "sendgrid", to, code: otp.code, providerData: response.data });
|
|
130
|
+
} catch (err) {
|
|
131
|
+
console.error(err);
|
|
132
|
+
return res.status(500).json({ error: "Failed to send OTP via SendGrid" });
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
|
|
112
137
|
// ------ OTP SMS -------
|
|
113
138
|
router.post('/auth/otp/send/sms/:to', async (req, res)=>{
|
|
114
139
|
try {
|
package/src/otp/index.js
CHANGED