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 CHANGED
@@ -15,7 +15,7 @@
15
15
  "uuid": "^9.0.1"
16
16
  },
17
17
  "name": "auth-verify",
18
- "version": "1.11.0",
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
@@ -344,6 +344,7 @@ otp.sender({
344
344
  })
345
345
  ```
346
346
  #### SMS sender
347
+ If you want reals sms sending you should add `mock: false`.
347
348
  ##### Using infobip:
348
349
  ```js
349
350
  otp.sender({
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
- // ----------- SMTP Provider -------------
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 { email, pass, host, port, secure, subject, text, html } = req.body.sender || {};
79
+ const { name, email, subject, text, html, apikey } = req.body.sender || {};
80
80
 
81
- if (!email || !pass || !host || !port) {
82
- return res.status(400).json({ error: "Missing sender email or pass or host or port" });
81
+ if (!email || !apikey) {
82
+ return res.status(400).json({ error: "Missing email or Brevo API key" });
83
83
  }
84
84
 
85
- auth.otp.sender({
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 info = await auth.otp.send(to, {
87
+ const payload = {
88
+ sender: { name: name || "AuthVerify", email },
89
+ to: [{ email: to }],
95
90
  subject: subject || "Your OTP Code",
96
- text: text || "",
97
- html: html || ""
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
- return res.json({
101
- ok: true,
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
@@ -204,7 +204,7 @@ class OTPManager {
204
204
  from: this.senderConfig.sender,
205
205
  to,
206
206
  text: text || `Your OTP is ${this.code}`,
207
- mock: this.senderConfig.mock ?? true,
207
+ mock: this.senderConfig.mock ?? false,
208
208
  });
209
209
 
210
210
  this.recieverConfig = options;