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 { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { Octicons } from "@expo/vector-icons";
|
import { Octicons } from "@expo/vector-icons";
|
||||||
import { router, Stack } from "expo-router";
|
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 { Image, SafeAreaView, ScrollView, Text, View } from "react-native";
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
|
||||||
export default function Profile() {
|
export default function Profile() {
|
||||||
const { signOut, token } = useAuthSession()
|
const { signOut, token, decryptToken } = useAuthSession()
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const entities = useSelector((state: any) => state.entities)
|
const entities = useSelector((state: any) => state.entities)
|
||||||
|
const [error, setError] = useState(false)
|
||||||
useEffect(() => {
|
const [role, setRole] = useState('')
|
||||||
apiGetProfile({ id: 'supadminAmalia' }).then((data) => dispatch(setEntities(data.data)));
|
|
||||||
}, [dispatch]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleUserLogin()
|
handleUserLogin()
|
||||||
}, []);
|
}, [dispatch]);
|
||||||
|
|
||||||
function handleUserLogin() {
|
async function handleUserLogin() {
|
||||||
console.log(token?.current)
|
const hasil = await decryptToken(String(token?.current))
|
||||||
var C = require("crypto-js");
|
apiGetProfile({ id: hasil }).then((data) => dispatch(setEntities(data.data)));
|
||||||
var Decrypted = C.AES.decrypt(token?.current, "your password");
|
setRole(entities.idUserRole)
|
||||||
var result = Decrypted.toString(C.enc.Utf8);
|
|
||||||
|
|
||||||
console.log(result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,7 +55,8 @@ export default function Profile() {
|
|||||||
<View style={{ flexDirection: 'column' }}>
|
<View style={{ flexDirection: 'column' }}>
|
||||||
<View style={[Styles.wrapHeadViewMember]}>
|
<View style={[Styles.wrapHeadViewMember]}>
|
||||||
<Image
|
<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]}
|
style={[Styles.userProfileBig]}
|
||||||
/>
|
/>
|
||||||
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10]}>{entities.name}</Text>
|
<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.p15]}>
|
||||||
<View style={[Styles.rowSpaceBetween]}>
|
<View style={[Styles.rowSpaceBetween]}>
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>Informasi</Text>
|
<Text style={[Styles.textDefaultSemiBold]}>Informasi</Text>
|
||||||
<Text style={[Styles.textLink]}>Edit</Text>
|
{
|
||||||
|
role != "developer" && <Text style={[Styles.textLink]}>Edit</Text>
|
||||||
|
}
|
||||||
</View>
|
</View>
|
||||||
<ItemDetailMember category="nik" value={entities.nik} />
|
<ItemDetailMember category="nik" value={entities.nik} />
|
||||||
<ItemDetailMember category="group" value={entities.group} />
|
<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 Styles from "@/constants/Styles"
|
||||||
import { apiCheckPhoneLogin, apiSendOtp } from "@/lib/api"
|
import { apiCheckPhoneLogin, apiSendOtp } from "@/lib/api"
|
||||||
|
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { Image, Text, ToastAndroid, View } from "react-native"
|
import { Image, Text, ToastAndroid, View } from "react-native"
|
||||||
import { ButtonForm } from "../buttonForm"
|
import { ButtonForm } from "../buttonForm"
|
||||||
@@ -25,6 +26,7 @@ export default function ViewLogin({ onValidate }: Props) {
|
|||||||
const responseOtp = await apiSendOtp({ phone: `62${phone}`, otp })
|
const responseOtp = await apiSendOtp({ phone: `62${phone}`, otp })
|
||||||
if (responseOtp == 200) {
|
if (responseOtp == 200) {
|
||||||
// localStorage.setItem('user', response.id)
|
// localStorage.setItem('user', response.id)
|
||||||
|
await AsyncStorage.setItem('user', response.id);
|
||||||
return onValidate({ phone: `62${phone}`, otp })
|
return onValidate({ phone: `62${phone}`, otp })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiSendOtp } from "@/lib/api";
|
import { apiSendOtp } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import CryptoES from "crypto-es";
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Image, Text, ToastAndroid, 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";
|
||||||
@@ -20,14 +20,19 @@ export default function ViewVerification({ phone, otp }: Props) {
|
|||||||
value,
|
value,
|
||||||
setValue,
|
setValue,
|
||||||
});
|
});
|
||||||
const { signIn } = useAuthSession();
|
const { signIn, encryptToken } = useAuthSession();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const login = (): void => {
|
const login = async () => {
|
||||||
var mytexttoEncryption = "contohLoginMobileDarmasaba"
|
const valueUser = await AsyncStorage.getItem('user');
|
||||||
const encrypted = CryptoES.AES.encrypt(mytexttoEncryption, "your password").toString();
|
if (valueUser != null) {
|
||||||
signIn(encrypted);
|
await AsyncStorage.removeItem('user');
|
||||||
|
const encrypted = await encryptToken(valueUser);
|
||||||
|
signIn(encrypted);
|
||||||
|
} else {
|
||||||
|
return ToastAndroid.show('Terjadi kesalahan', ToastAndroid.SHORT)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onCheckOtp = () => {
|
const onCheckOtp = () => {
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
import {router} from "expo-router";
|
import {router} from "expo-router";
|
||||||
import {createContext, MutableRefObject, ReactNode, useCallback, useContext, useEffect, useRef, useState} from 'react';
|
import {createContext, MutableRefObject, ReactNode, useCallback, useContext, useEffect, useRef, useState} from 'react';
|
||||||
|
import CryptoES from "crypto-es";
|
||||||
|
|
||||||
const AuthContext = createContext<{
|
const AuthContext = createContext<{
|
||||||
signIn: (arg0: string) => void;
|
signIn: (arg0: string) => void;
|
||||||
signOut: () => void
|
signOut: () => void
|
||||||
|
decryptToken: (arg0: string) => Promise<string>
|
||||||
|
encryptToken: (arg0: string) => Promise<string>
|
||||||
token: MutableRefObject<string | null> | null;
|
token: MutableRefObject<string | null> | null;
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
}>({
|
}>({
|
||||||
signIn: () => null,
|
signIn: () => null,
|
||||||
signOut: () => null,
|
signOut: () => null,
|
||||||
|
decryptToken: () => Promise.resolve(''),
|
||||||
|
encryptToken: () => Promise.resolve(''),
|
||||||
token: null,
|
token: null,
|
||||||
isLoading: true
|
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) => {
|
const signIn = useCallback(async (token: string) => {
|
||||||
await AsyncStorage.setItem('@token', token);
|
await AsyncStorage.setItem('@token', token);
|
||||||
tokenRef.current = token;
|
tokenRef.current = token;
|
||||||
@@ -49,6 +66,8 @@ export default function AuthProvider ({children}:{children: ReactNode}): ReactN
|
|||||||
signIn,
|
signIn,
|
||||||
signOut,
|
signOut,
|
||||||
token: tokenRef,
|
token: tokenRef,
|
||||||
|
decryptToken,
|
||||||
|
encryptToken,
|
||||||
isLoading
|
isLoading
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user