Fix Login KodeOtp WA

This commit is contained in:
2026-02-26 14:12:54 +08:00
parent 223b85a714
commit a152eaf984
2 changed files with 26 additions and 29 deletions

View File

@@ -33,37 +33,34 @@ export async function POST(req: Request) {
const codeOtp = randomOTP(); const codeOtp = randomOTP();
const otpNumber = Number(codeOtp); const otpNumber = Number(codeOtp);
// ✅ PERBAIKAN: Gunakan format pesan yang lebih sederhana const waMessage = `Website Desa Darmasaba - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun Admin lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`;
// Hapus karakter khusus yang bisa bikin masalah const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`;
// const waMessage = `Website Desa Darmasaba\nKode verifikasi Anda ${codeOtp}`;
// // ✅ OPSI 1: Tanpa encoding (coba dulu ini) console.log("🔍 Debug WA URL:", waUrl);
// const waUrl = `https://wa.wibudev.com/code?nom=${nomor}&text=${waMessage}`;
// ✅ OPSI 2: Dengan encoding (kalau opsi 1 gagal) try {
// const waUrl = `https://wa.wibudev.com/code?nom=${nomor}&text=${encodeURIComponent(waMessage)}`; const res = await fetch(waUrl);
const sendWa = await res.json();
// ✅ OPSI 3: Encoding manual untuk URL-safe (alternatif terakhir) console.log("📱 WA Response:", sendWa);
// const encodedMessage = waMessage.replace(/\n/g, '%0A').replace(/ /g, '%20');
// const waUrl = `https://wa.wibudev.com/code?nom=${nomor}&text=${encodedMessage}`;
// console.log("🔍 Debug WA URL:", waUrl); // Untuk debugging if (sendWa.status !== "success") {
console.error("❌ WA Service Error:", sendWa);
// const res = await fetch(waUrl); return NextResponse.json(
// const sendWa = await res.json(); {
success: false,
// console.log("📱 WA Response:", sendWa); // Debug response message: "Gagal mengirim OTP via WhatsApp",
debug: sendWa
// if (sendWa.status !== "success") { },
// return NextResponse.json( { status: 400 }
// { );
// success: false, }
// message: "Gagal mengirim OTP via WhatsApp", } catch (waError) {
// debug: sendWa // Tampilkan error detail console.error("❌ Fetch WA Error:", waError);
// }, return NextResponse.json(
// { status: 400 } { success: false, message: "Terjadi kesalahan saat mengirim WA" },
// ); { status: 500 }
// } );
}
const createOtpId = await prisma.kodeOtp.create({ const createOtpId = await prisma.kodeOtp.create({
data: { nomor, otp: otpNumber, isActive: true }, data: { nomor, otp: otpNumber, isActive: true },

View File

@@ -19,7 +19,7 @@ export async function POST(req: Request) {
const otpNumber = Number(codeOtp); const otpNumber = Number(codeOtp);
// Kirim OTP via WhatsApp // Kirim OTP via WhatsApp
const waMessage = `Kode verifikasi Anda: ${codeOtp}`; const waMessage = `Website Desa Darmasaba - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun Admin lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`;
const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`; const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`;
const waRes = await fetch(waUrl); const waRes = await fetch(waUrl);
const waData = await waRes.json(); const waData = await waRes.json();