-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathotp_send.js
More file actions
44 lines (40 loc) · 1.37 KB
/
otp_send.js
File metadata and controls
44 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Send OTP via SMS / WhatsApp / Email (minimal script)
* Usage:
* node otp_send.js sms +9665XXXXXXXX
* node otp_send.js whatsapp +9665XXXXXXXX
* node otp_send.js email user@example.com
* Env:
* AUTHENTICA_API_KEY (required)
* BASE_URL (optional, defaults to https://api.authentica.sa)
*/
const BASE_URL = process.env.BASE_URL || 'https://api.authentica.sa';
const API_KEY = process.env.AUTHENTICA_API_KEY || 'YOUR_API_KEY';
const [, , method = 'sms', recipient] = process.argv;
if (!recipient) {
console.error('Usage: node otp_send.js <sms|whatsapp|email> <phone|email>');
process.exit(1);
}
const body = method === 'email' ? { method, email: recipient } : { method, phone: recipient };
(async () => {
try {
const res = await fetch(`${BASE_URL}/api/v2/send-otp`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Authorization': API_KEY,
},
body: JSON.stringify(body),
});
const json = await res.json().catch(() => ({}));
if (!res.ok) {
console.error('Error:', res.status, json);
process.exit(1);
}
console.log('OTP sent:', { success: true });
} catch (e) {
console.error('Network error:', e.message);
process.exit(1);
}
})();