Refactor SMS notification handling to use environment variables

- Updated SMS API calls in auth-actions.ts, user-actions.ts, and check-devices/route.ts to utilize environment variables for the base URL and API key.
- Changed request body parameters from 'text' to 'message' and added 'check_delivery' to improve SMS delivery tracking.

These changes enhance security and maintainability by centralizing configuration settings.
This commit is contained in:
i701 2024-12-25 21:22:30 +05:00
parent 75ad431160
commit 5c167e436d
3 changed files with 12 additions and 9 deletions

View File

@ -132,15 +132,16 @@ export async function signup(_actionState: ActionState, formData: FormData) {
export const sendOtp = async (phoneNumber: string, code: string) => { export const sendOtp = async (phoneNumber: string, code: string) => {
// Implement sending OTP code via SMS // Implement sending OTP code via SMS
console.log("Send OTP server fn", phoneNumber, code); console.log("Send OTP server fn", phoneNumber, code);
const respose = await fetch("https://smsapi.sarlink.link/send", { const respose = await fetch(`${process.env.SMS_API_BASE_URL}/api/sms`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${process.env.SMS_API_KEY}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
api_key: process.env.SMS_API_KEY, check_delivery: false,
number: phoneNumber, number: phoneNumber,
text: `Your OTP code is ${code}`, message: `Your OTP code is ${code}`,
}), }),
}); });
const data = await respose.json(); const data = await respose.json();

View File

@ -80,15 +80,16 @@ export const SendUserRejectionDetailSMS = async ({
details: string; details: string;
phoneNumber: string; phoneNumber: string;
}) => { }) => {
const respose = await fetch("https://smsapi.sarlink.link/send", { const respose = await fetch(`${process.env.SMS_API_BASE_URL}/api/sms`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${process.env.SMS_API_KEY}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
api_key: process.env.SMS_API_KEY, check_delivery: false,
number: phoneNumber, number: phoneNumber,
text: details, message: details,
}), }),
}); });
const data = await respose.json(); const data = await respose.json();

View File

@ -128,15 +128,16 @@ async function sendNotifySms(
phoneNumber: string, phoneNumber: string,
deviceName?: string, deviceName?: string,
) { ) {
const respose = await fetch("https://smsapi.sarlink.link/send", { const respose = await fetch(`${process.env.SMS_API_BASE_URL}/api/sms`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${process.env.SMS_API_KEY}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
api_key: process.env.SMS_API_KEY, check_delivery: false,
number: phoneNumber, number: phoneNumber,
text: `REMINDER! Your device [${deviceName}] will expire on ${new Date(expireDate)}.`, message: `REMINDER! Your device [${deviceName}] will expire on ${new Date(expireDate)}.`,
}), }),
}); });
const data = await respose.json(); const data = await respose.json();