Feat validasi mobile otp
modified: context/AuthContext.tsx
modified: screens/Authentication/VerificationView.tsx
modified: service/api-config.ts
### No Issue
This commit is contained in:
@@ -22,7 +22,7 @@ type AuthContextType = {
|
|||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
isUserActive: boolean;
|
isUserActive: boolean;
|
||||||
loginWithNomor: (nomor: string) => Promise<boolean>;
|
loginWithNomor: (nomor: string) => Promise<boolean>;
|
||||||
validateOtp: (nomor: string) => Promise<any>;
|
validateOtp: (nomor: string, code: string) => Promise<any>;
|
||||||
logout: () => Promise<void>;
|
logout: () => Promise<void>;
|
||||||
registerUser: (userData: {
|
registerUser: (userData: {
|
||||||
username: string;
|
username: string;
|
||||||
@@ -97,10 +97,10 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// --- 2. Validasi OTP & cek user ---
|
// --- 2. Validasi OTP & cek user ---
|
||||||
const validateOtp = async (nomor: string) => {
|
const validateOtp = async (nomor: string, code: string) => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const response = await apiValidationCode({ nomor: nomor });
|
const response = await apiValidationCode({ nomor: nomor, code: code });
|
||||||
const { token } = response;
|
const { token } = response;
|
||||||
console.log("[RESPONSE VALIDASI OTP]", JSON.stringify(response, null, 2));
|
console.log("[RESPONSE VALIDASI OTP]", JSON.stringify(response, null, 2));
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ export default function VerificationView() {
|
|||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
const [recodeOtp, setRecodeOtp] = useState<boolean>(false);
|
const [recodeOtp, setRecodeOtp] = useState<boolean>(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 =
|
const isReviewMode =
|
||||||
typeof window !== "undefined" && // pastikan di browser/production
|
process.env.NODE_ENV === "development" &&
|
||||||
process.env.NODE_ENV === "production" &&
|
|
||||||
nomor === "6282340374412";
|
nomor === "6282340374412";
|
||||||
|
|
||||||
// --- Context ---
|
// --- Context ---
|
||||||
@@ -37,10 +37,6 @@ export default function VerificationView() {
|
|||||||
// Hanya jalankan logika OTP normal jika BUKAN review mode
|
// Hanya jalankan logika OTP normal jika BUKAN review mode
|
||||||
onLoadCheckCodeOtp();
|
onLoadCheckCodeOtp();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[NODE_ENV]:", process.env.NODE_ENV);
|
|
||||||
console.log("[isReviewMode]:", isReviewMode);
|
|
||||||
console.log("[nomor]:", nomor);
|
|
||||||
}, [recodeOtp, isReviewMode]);
|
}, [recodeOtp, isReviewMode]);
|
||||||
|
|
||||||
async function onLoadCheckCodeOtp() {
|
async function onLoadCheckCodeOtp() {
|
||||||
@@ -85,29 +81,30 @@ export default function VerificationView() {
|
|||||||
|
|
||||||
const handleVerification = async () => {
|
const handleVerification = async () => {
|
||||||
if (isReviewMode) {
|
if (isReviewMode) {
|
||||||
// ✅ VERIFIKASI OTOMATIS UNTUK APPLE REVIEW
|
// ✅ VERIFIKASI OTOMATIS UNTUK APPLE REVIEW (Development Only)
|
||||||
if (inputOtp === "1234") {
|
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 {
|
|
||||||
Toast.show({ type: "error", text1: "Kode OTP tidak sesuai" });
|
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)
|
// 🔁 VERIFIKASI NORMAL (untuk pengguna sungguhan)
|
||||||
try {
|
try {
|
||||||
await validateOtp(nomor as string);
|
await validateOtp(nomor as string, inputOtp);
|
||||||
return
|
return;
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.log("Error verification", error);
|
console.log("Error verification", error);
|
||||||
Toast.show({ type: "error", text1: "Gagal verifikasi" });
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: error.response?.data?.message || "Gagal verifikasi",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,16 @@ export async function apiCheckCodeOtp({ kodeId }: { kodeId: string }) {
|
|||||||
return response.data;
|
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`, {
|
const response = await apiConfig.post(`/auth/mobile-validasi`, {
|
||||||
nomor: nomor,
|
nomor: nomor,
|
||||||
|
code: code,
|
||||||
});
|
});
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user