upd: profile
Deskripsi: - profile sudah sesuai dg role user login dan id user login No Issues
This commit is contained in:
@@ -8,30 +8,25 @@ import { setEntities } from "@/lib/entitiesSlice";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import { Octicons } from "@expo/vector-icons";
|
||||
import { router, Stack } from "expo-router";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Image, SafeAreaView, ScrollView, Text, View } from "react-native";
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
export default function Profile() {
|
||||
const { signOut, token } = useAuthSession()
|
||||
const { signOut, token, decryptToken } = useAuthSession()
|
||||
const dispatch = useDispatch()
|
||||
const entities = useSelector((state: any) => state.entities)
|
||||
|
||||
useEffect(() => {
|
||||
apiGetProfile({ id: 'supadminAmalia' }).then((data) => dispatch(setEntities(data.data)));
|
||||
}, [dispatch]);
|
||||
const [error, setError] = useState(false)
|
||||
const [role, setRole] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
handleUserLogin()
|
||||
}, []);
|
||||
}, [dispatch]);
|
||||
|
||||
function handleUserLogin() {
|
||||
console.log(token?.current)
|
||||
var C = require("crypto-js");
|
||||
var Decrypted = C.AES.decrypt(token?.current, "your password");
|
||||
var result = Decrypted.toString(C.enc.Utf8);
|
||||
|
||||
console.log(result)
|
||||
async function handleUserLogin() {
|
||||
const hasil = await decryptToken(String(token?.current))
|
||||
apiGetProfile({ id: hasil }).then((data) => dispatch(setEntities(data.data)));
|
||||
setRole(entities.idUserRole)
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +55,8 @@ export default function Profile() {
|
||||
<View style={{ flexDirection: 'column' }}>
|
||||
<View style={[Styles.wrapHeadViewMember]}>
|
||||
<Image
|
||||
source={{ uri: `https://wibu-storage.wibudev.com/api/files/${entities.img}` }}
|
||||
source={error ? require("../../assets/images/user.jpg") : { uri: `https://wibu-storage.wibudev.com/api/files/${entities.img}` }}
|
||||
onError={() => { setError(true) }}
|
||||
style={[Styles.userProfileBig]}
|
||||
/>
|
||||
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10]}>{entities.name}</Text>
|
||||
@@ -69,7 +65,9 @@ export default function Profile() {
|
||||
<View style={[Styles.p15]}>
|
||||
<View style={[Styles.rowSpaceBetween]}>
|
||||
<Text style={[Styles.textDefaultSemiBold]}>Informasi</Text>
|
||||
<Text style={[Styles.textLink]}>Edit</Text>
|
||||
{
|
||||
role != "developer" && <Text style={[Styles.textLink]}>Edit</Text>
|
||||
}
|
||||
</View>
|
||||
<ItemDetailMember category="nik" value={entities.nik} />
|
||||
<ItemDetailMember category="group" value={entities.group} />
|
||||
|
||||
BIN
assets/images/user.jpg
Normal file
BIN
assets/images/user.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.8 KiB |
@@ -1,5 +1,6 @@
|
||||
import Styles from "@/constants/Styles"
|
||||
import { apiCheckPhoneLogin, apiSendOtp } from "@/lib/api"
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||
import { useState } from "react"
|
||||
import { Image, Text, ToastAndroid, View } from "react-native"
|
||||
import { ButtonForm } from "../buttonForm"
|
||||
@@ -25,6 +26,7 @@ export default function ViewLogin({ onValidate }: Props) {
|
||||
const responseOtp = await apiSendOtp({ phone: `62${phone}`, otp })
|
||||
if (responseOtp == 200) {
|
||||
// localStorage.setItem('user', response.id)
|
||||
await AsyncStorage.setItem('user', response.id);
|
||||
return onValidate({ phone: `62${phone}`, otp })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Styles from "@/constants/Styles";
|
||||
import { apiSendOtp } from "@/lib/api";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import CryptoES from "crypto-es";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { useState } from "react";
|
||||
import { Image, Text, ToastAndroid, View } from "react-native";
|
||||
import { CodeField, Cursor, useBlurOnFulfill, useClearByFocusCell } from "react-native-confirmation-code-field";
|
||||
@@ -20,14 +20,19 @@ export default function ViewVerification({ phone, otp }: Props) {
|
||||
value,
|
||||
setValue,
|
||||
});
|
||||
const { signIn } = useAuthSession();
|
||||
const { signIn, encryptToken } = useAuthSession();
|
||||
|
||||
|
||||
|
||||
const login = (): void => {
|
||||
var mytexttoEncryption = "contohLoginMobileDarmasaba"
|
||||
const encrypted = CryptoES.AES.encrypt(mytexttoEncryption, "your password").toString();
|
||||
signIn(encrypted);
|
||||
const login = async () => {
|
||||
const valueUser = await AsyncStorage.getItem('user');
|
||||
if (valueUser != null) {
|
||||
await AsyncStorage.removeItem('user');
|
||||
const encrypted = await encryptToken(valueUser);
|
||||
signIn(encrypted);
|
||||
} else {
|
||||
return ToastAndroid.show('Terjadi kesalahan', ToastAndroid.SHORT)
|
||||
}
|
||||
}
|
||||
|
||||
const onCheckOtp = () => {
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import {router} from "expo-router";
|
||||
import {createContext, MutableRefObject, ReactNode, useCallback, useContext, useEffect, useRef, useState} from 'react';
|
||||
import CryptoES from "crypto-es";
|
||||
|
||||
const AuthContext = createContext<{
|
||||
signIn: (arg0: string) => void;
|
||||
signOut: () => void
|
||||
decryptToken: (arg0: string) => Promise<string>
|
||||
encryptToken: (arg0: string) => Promise<string>
|
||||
token: MutableRefObject<string | null> | null;
|
||||
isLoading: boolean
|
||||
}>({
|
||||
signIn: () => null,
|
||||
signOut: () => null,
|
||||
decryptToken: () => Promise.resolve(''),
|
||||
encryptToken: () => Promise.resolve(''),
|
||||
token: null,
|
||||
isLoading: true
|
||||
});
|
||||
@@ -31,6 +36,18 @@ export default function AuthProvider ({children}:{children: ReactNode}): ReactN
|
||||
})()
|
||||
}, []);
|
||||
|
||||
const decryptToken = (async (token: string) => {
|
||||
var C = require("crypto-js");
|
||||
var Decrypted = C.AES.decrypt(token, "your password");
|
||||
var result = Decrypted.toString(C.enc.Utf8);
|
||||
return result
|
||||
})
|
||||
|
||||
const encryptToken = (async (token: string) => {
|
||||
var result = CryptoES.AES.encrypt(token, "your password").toString();
|
||||
return result
|
||||
})
|
||||
|
||||
const signIn = useCallback(async (token: string) => {
|
||||
await AsyncStorage.setItem('@token', token);
|
||||
tokenRef.current = token;
|
||||
@@ -49,6 +66,8 @@ export default function AuthProvider ({children}:{children: ReactNode}): ReactN
|
||||
signIn,
|
||||
signOut,
|
||||
token: tokenRef,
|
||||
decryptToken,
|
||||
encryptToken,
|
||||
isLoading
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user