refactor: standarisasi antarmuka fungsi login dan pengambilan OTP
Mengubah parameter fungsi auth_funLogin dan auth_getKodeOtpById di backend untuk menggunakan objek, meningkatkan konsistensi dan memudahkan pemahaman tentang data yang diproses. Selain itu, memperbaiki struktur respons fungsi untuk menambahkan dalam output, memperjelas sumber terjadinya error. - Di , fungsi auth_funLogin diubah untuk menerima sebuah objek daripada hanya . - Di , perubahan variabel ke untuk menyelaraskan dengan parameter terbaru dari fungsi yang diinvokasi.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { randomOTP } from "./rondom_otp";
|
||||
|
||||
export async function auth_funLogin(nomor: string) {
|
||||
export async function auth_funLogin({ nomor }: { nomor: string }) {
|
||||
const codeOtp = randomOTP();
|
||||
// console.log(nomor)
|
||||
|
||||
@@ -17,7 +17,7 @@ export async function auth_funLogin(nomor: string) {
|
||||
|
||||
const sendWa = await res.json();
|
||||
if (sendWa.status !== "success")
|
||||
return { status: 400, message: "WA Tidak Terdaftar" };
|
||||
return { status: 400, message: "WA Tidak Terdaftar", nomorUser: {} };
|
||||
|
||||
const createOtpId = await prisma.kodeOtp.create({
|
||||
data: {
|
||||
@@ -26,15 +26,16 @@ export async function auth_funLogin(nomor: string) {
|
||||
},
|
||||
});
|
||||
|
||||
if (!createOtpId) return { status: 400, message: "Gagal Membuat Kode OTP" };
|
||||
if (!createOtpId)
|
||||
return { status: 400, message: "Gagal Membuat Kode OTP", nomorUser: {} };
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
message: "Kode Verifikasi Dikirim",
|
||||
kodeOtpId: createOtpId.id,
|
||||
nomorUser: nomor,
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return { status: 500, message: "Server Error !!!" };
|
||||
return { status: 500, message: "Server Error !!!", nomorUser: {} };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export async function auth_getKodeOtpById(otpId: string) {
|
||||
export async function auth_getKodeOtpById({nomor}: {nomor: string}) {
|
||||
const data = await prisma.kodeOtp.findFirst({
|
||||
where: {
|
||||
id: otpId,
|
||||
nomor: nomor,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -34,16 +34,14 @@ export default function Login() {
|
||||
const [isError, setError] = useState(false);
|
||||
|
||||
async function onLogin() {
|
||||
const nomorHp = phone.substring(1);
|
||||
const nomor = phone.substring(1);
|
||||
if (nomor.length <= 4) return setError(true);
|
||||
|
||||
if (nomorHp.length <= 4) return setError(true);
|
||||
|
||||
const res = await auth_funLogin(nomorHp);
|
||||
const res = await auth_funLogin({ nomor: nomor });
|
||||
if (res.status === 200) {
|
||||
setLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
setKodeId(res.kodeOtpId);
|
||||
router.push(RouterAuth.validasi + res.kodeOtpId);
|
||||
router.push(RouterAuth.validasi + res.nomorUser, { scroll: false });
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(res.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user