diff --git a/context/AuthContext.tsx b/context/AuthContext.tsx index 8dd2818..a03f240 100644 --- a/context/AuthContext.tsx +++ b/context/AuthContext.tsx @@ -22,7 +22,7 @@ type AuthContextType = { isAdmin: boolean; isUserActive: boolean; loginWithNomor: (nomor: string) => Promise; - validateOtp: (nomor: string) => Promise; + validateOtp: (nomor: string, code: string) => Promise; logout: () => Promise; registerUser: (userData: { username: string; @@ -97,10 +97,10 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { }; // --- 2. Validasi OTP & cek user --- - const validateOtp = async (nomor: string) => { + const validateOtp = async (nomor: string, code: string) => { try { setIsLoading(true); - const response = await apiValidationCode({ nomor: nomor }); + const response = await apiValidationCode({ nomor: nomor, code: code }); const { token } = response; console.log("[RESPONSE VALIDASI OTP]", JSON.stringify(response, null, 2)); diff --git a/screens/Authentication/VerificationView.tsx b/screens/Authentication/VerificationView.tsx index b2f6087..c75b4a2 100644 --- a/screens/Authentication/VerificationView.tsx +++ b/screens/Authentication/VerificationView.tsx @@ -21,10 +21,10 @@ export default function VerificationView() { const [loading, setLoading] = useState(false); const [recodeOtp, setRecodeOtp] = useState(false); - // 🔑 DETEKSI MODE REVIEW (HANYA UNTUK NOMOR DEMO & PRODUCTION) + // 🔑 DETEKSI MODE REVIEW (HANYA UNTUK NOMOR DEMO & DEVELOPMENT BUILD) + // Menggunakan Constants.expoConfig untuk mendeteksi development build const isReviewMode = - typeof window !== "undefined" && // pastikan di browser/production - process.env.NODE_ENV === "production" && + process.env.NODE_ENV === "development" && nomor === "6282340374412"; // --- Context --- @@ -37,10 +37,6 @@ export default function VerificationView() { // Hanya jalankan logika OTP normal jika BUKAN review mode onLoadCheckCodeOtp(); } - - console.log("[NODE_ENV]:", process.env.NODE_ENV); - console.log("[isReviewMode]:", isReviewMode); - console.log("[nomor]:", nomor); }, [recodeOtp, isReviewMode]); async function onLoadCheckCodeOtp() { @@ -85,29 +81,30 @@ export default function VerificationView() { const handleVerification = async () => { if (isReviewMode) { - // ✅ VERIFIKASI OTOMATIS UNTUK APPLE REVIEW - if (inputOtp === "1234") { - try { - await validateOtp(nomor as string); - - return; - } catch (error) { - console.log("Error verification", error); - Toast.show({ type: "error", text1: "Gagal verifikasi" }); - } - } else { + // ✅ VERIFIKASI OTOMATIS UNTUK APPLE REVIEW (Development Only) + if (inputOtp !== "1234") { Toast.show({ type: "error", text1: "Kode OTP tidak sesuai" }); + return; + } + try { + await validateOtp(nomor as string, inputOtp); + return; + } catch (error) { + console.log("Error verification", error); + Toast.show({ type: "error", text1: "Gagal verifikasi" }); } - return; } // 🔁 VERIFIKASI NORMAL (untuk pengguna sungguhan) try { - await validateOtp(nomor as string); - return - } catch (error) { + await validateOtp(nomor as string, inputOtp); + return; + } catch (error: any) { console.log("Error verification", error); - Toast.show({ type: "error", text1: "Gagal verifikasi" }); + Toast.show({ + type: "error", + text1: error.response?.data?.message || "Gagal verifikasi", + }); } }; diff --git a/service/api-config.ts b/service/api-config.ts index 71485be..f4dc7ef 100644 --- a/service/api-config.ts +++ b/service/api-config.ts @@ -45,9 +45,16 @@ export async function apiCheckCodeOtp({ kodeId }: { kodeId: string }) { return response.data; } -export async function apiValidationCode({ nomor }: { nomor: string }) { +export async function apiValidationCode({ + nomor, + code, +}: { + nomor: string; + code: string; +}) { const response = await apiConfig.post(`/auth/mobile-validasi`, { nomor: nomor, + code: code, }); return response.data; }