upd : login
Deskripsi: - done resend otp - done check otp - blm selesai localstorage nyimpen user id sementara No Issues
This commit is contained in:
@@ -23,8 +23,10 @@ export default function ViewLogin({ onValidate }: Props) {
|
|||||||
if (response.success) {
|
if (response.success) {
|
||||||
const otp = Math.floor(1000 + Math.random() * 9000)
|
const otp = Math.floor(1000 + Math.random() * 9000)
|
||||||
const responseOtp = await apiSendOtp({ phone: `62${phone}`, otp })
|
const responseOtp = await apiSendOtp({ phone: `62${phone}`, otp })
|
||||||
console.log(responseOtp)
|
if (responseOtp == 200) {
|
||||||
// return onValidate({ phone: `62${phone}`, otp })
|
// localStorage.setItem('user', response.id)
|
||||||
|
return onValidate({ phone: `62${phone}`, otp })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ToastAndroid.show(response.message, ToastAndroid.SHORT)
|
return ToastAndroid.show(response.message, ToastAndroid.SHORT)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
|
import { apiSendOtp } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import CryptoES from "crypto-es";
|
import CryptoES from "crypto-es";
|
||||||
import { useState } from "react";
|
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 { CodeField, Cursor, useBlurOnFulfill, useClearByFocusCell } from "react-native-confirmation-code-field";
|
||||||
import { ButtonForm } from "../buttonForm";
|
import { ButtonForm } from "../buttonForm";
|
||||||
|
|
||||||
@@ -13,30 +14,43 @@ type Props = {
|
|||||||
|
|
||||||
export default function ViewVerification({ phone, otp }: Props) {
|
export default function ViewVerification({ phone, otp }: Props) {
|
||||||
const [value, setValue] = useState('');
|
const [value, setValue] = useState('');
|
||||||
|
const [otpFix, setOtpFix] = useState(otp)
|
||||||
const ref = useBlurOnFulfill({ value, cellCount: 4 });
|
const ref = useBlurOnFulfill({ value, cellCount: 4 });
|
||||||
const [props, getCellOnLayoutHandler] = useClearByFocusCell({
|
const [props, getCellOnLayoutHandler] = useClearByFocusCell({
|
||||||
value,
|
value,
|
||||||
setValue,
|
setValue,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { signIn } = useAuthSession();
|
const { signIn } = useAuthSession();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const login = (): void => {
|
const login = (): void => {
|
||||||
const random: string = 'contohLoginMobileDarmasaba';
|
|
||||||
var mytexttoEncryption = "contohLoginMobileDarmasaba"
|
var mytexttoEncryption = "contohLoginMobileDarmasaba"
|
||||||
const encrypted = CryptoES.AES.encrypt(mytexttoEncryption, "your password").toString();
|
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);
|
signIn(encrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
const onCheckOtp = () => {
|
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 (
|
return (
|
||||||
@@ -73,11 +87,10 @@ export default function ViewVerification({ phone, otp }: Props) {
|
|||||||
/>
|
/>
|
||||||
<ButtonForm
|
<ButtonForm
|
||||||
text="SUBMIT"
|
text="SUBMIT"
|
||||||
// onPress={() => { router.push("/home") }}
|
onPress={() => { onCheckOtp() }}
|
||||||
onPress={login}
|
|
||||||
/>
|
/>
|
||||||
<Text style={[Styles.textInformation, Styles.mt05, Styles.cDefault, { textAlign: 'center' }]}>
|
<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>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user