mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-02-22 17:22:17 +00:00
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:
parent
75ad431160
commit
5c167e436d
@ -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();
|
||||||
|
@ -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();
|
||||||
|
@ -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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user