Fix: validasi
Deksripsi: - Penambahan fitur kirim ulang kode ## No Issue
This commit is contained in:
40
src/app_modules/auth/fun/fun_resend_code.ts
Normal file
40
src/app_modules/auth/fun/fun_resend_code.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import { randomOTP } from "./rondom_otp";
|
||||
|
||||
export async function auth_funResendCode({ nomor }: { nomor: string }) {
|
||||
const codeOtp = randomOTP();
|
||||
|
||||
try {
|
||||
const res = await fetch(
|
||||
`https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.
|
||||
\n
|
||||
>> Kode OTP anda: ${codeOtp}.
|
||||
`
|
||||
);
|
||||
|
||||
const sendWa = await res.json();
|
||||
if (sendWa.status !== "success")
|
||||
return { status: 400, message: "WA Tidak Terdaftar", kodeId: {} };
|
||||
|
||||
const createOtpId = await prisma.kodeOtp.create({
|
||||
data: {
|
||||
nomor: nomor,
|
||||
otp: codeOtp,
|
||||
},
|
||||
});
|
||||
|
||||
if (!createOtpId)
|
||||
return { status: 400, message: "Gagal Membuat Kode OTP", kodeId: {} };
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
message: "Kode Verifikasi Dikirim",
|
||||
kodeId: createOtpId.id,
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return { status: 500, message: "Server Error !!!", kodeId: {} };
|
||||
}
|
||||
}
|
||||
3
src/app_modules/auth/fun/index.ts
Normal file
3
src/app_modules/auth/fun/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { auth_funResendCode } from "./fun_resend_code";
|
||||
|
||||
export { auth_funResendCode };
|
||||
Reference in New Issue
Block a user