upd : login

Deskripsi:
- done resend otp
- done check otp
- blm selesai localstorage nyimpen user id sementara

No Issues
This commit is contained in:
amel
2025-04-17 17:28:04 +08:00
parent b6b23742d2
commit 043d15bdd9
2 changed files with 29 additions and 14 deletions

View File

@@ -23,8 +23,10 @@ export default function ViewLogin({ onValidate }: Props) {
if (response.success) {
const otp = Math.floor(1000 + Math.random() * 9000)
const responseOtp = await apiSendOtp({ phone: `62${phone}`, otp })
console.log(responseOtp)
// return onValidate({ phone: `62${phone}`, otp })
if (responseOtp == 200) {
// localStorage.setItem('user', response.id)
return onValidate({ phone: `62${phone}`, otp })
}
}
return ToastAndroid.show(response.message, ToastAndroid.SHORT)
} catch (error) {

View File

@@ -1,8 +1,9 @@
import Styles from "@/constants/Styles";
import { apiSendOtp } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
import CryptoES from "crypto-es";
import { useState } from "react";
import { Image, Text, View } from "react-native";
import { Image, Text, ToastAndroid, View } from "react-native";
import { CodeField, Cursor, useBlurOnFulfill, useClearByFocusCell } from "react-native-confirmation-code-field";
import { ButtonForm } from "../buttonForm";
@@ -13,30 +14,43 @@ type Props = {
export default function ViewVerification({ phone, otp }: Props) {
const [value, setValue] = useState('');
const [otpFix, setOtpFix] = useState(otp)
const ref = useBlurOnFulfill({ value, cellCount: 4 });
const [props, getCellOnLayoutHandler] = useClearByFocusCell({
value,
setValue,
});
const { signIn } = useAuthSession();
const login = (): void => {
const random: string = 'contohLoginMobileDarmasaba';
var mytexttoEncryption = "contohLoginMobileDarmasaba"
const encrypted = CryptoES.AES.encrypt(mytexttoEncryption, "your password").toString();
// var C = require("crypto-js");
// var Decrypted = C.AES.decrypt(encrypted, "your password");
// var result = Decrypted.toString(C.enc.Utf8);
signIn(encrypted);
}
const onCheckOtp = () => {
if (value === otp.toString()) {
if (value === otpFix.toString()) {
login()
} else {
return ToastAndroid.show('Kode OTP tidak sesuai', ToastAndroid.SHORT)
}
}
const resendOtp = () => {
const resendOtp = async () => {
try {
const otpNew = Math.floor(1000 + Math.random() * 9000)
setOtpFix(otpNew)
const responseOtp = await apiSendOtp({ phone, otp: otpNew })
if (responseOtp == 200) {
return ToastAndroid.show('Kode OTP berhasil dikirim ulang', ToastAndroid.SHORT)
}
return ToastAndroid.show('Terjadi kesalahan dalam mengirim kode OTP', ToastAndroid.SHORT)
} catch (error) {
console.error('Error fetching data:', error);
return ToastAndroid.show('Terjadi kesalahan', ToastAndroid.SHORT)
}
}
return (
@@ -73,11 +87,10 @@ export default function ViewVerification({ phone, otp }: Props) {
/>
<ButtonForm
text="SUBMIT"
// onPress={() => { router.push("/home") }}
onPress={login}
onPress={() => { onCheckOtp() }}
/>
<Text style={[Styles.textInformation, Styles.mt05, Styles.cDefault, { textAlign: 'center' }]}>
Tidak Menerima kode verifikasi? Kirim Ulang
Tidak Menerima kode verifikasi? <Text onPress={() => { resendOtp() }}>Kirim Ulang</Text>
</Text>
</View>
</>