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:
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) => {
// Implement sending OTP code via SMS
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",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.SMS_API_KEY}`,
},
body: JSON.stringify({
api_key: process.env.SMS_API_KEY,
check_delivery: false,
number: phoneNumber,
text: `Your OTP code is ${code}`,
message: `Your OTP code is ${code}`,
}),
});
const data = await respose.json();