Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added encrypted storage methods #236

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"react-native-datepicker": "^1.7.2",
"react-native-device-info": "^10.8.0",
"react-native-element-dropdown": "^2.0.0",
"react-native-encrypted-storage": "^4.0.3",
"react-native-floating-action": "^1.22.0",
"react-native-gesture-handler": "^1.10.3",
"react-native-image-picker": "^4.7.1",
Expand Down
1 change: 0 additions & 1 deletion src/screens/AuthScreen/AuthScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ const AuthScreen = () => {
onPress={activateCamera}
/>
</View>

{cameraActive && (
<CameraScreen
style={StyleSheet.absoluteFill}
Expand Down
47 changes: 47 additions & 0 deletions src/utils/dataStore.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import EncryptedStorage from 'react-native-encrypted-storage';
import { Toast } from 'react-native-toast-message/lib/src/Toast';

export const storeData = async (name: string, value: string) => {
try {
Expand All @@ -16,3 +18,48 @@ export const getData = async (item: string) => {
})
.catch((err) => console.log(err));
};

export enum StorageKey {
TOKEN = 'TOKEN',
}

export const Storage = {
async setItem(key: string, value: string): Promise<void> {
await EncryptedStorage.setItem(key, value.toString());
},

async getItem(key: string): Promise<string | null> {
return EncryptedStorage.getItem(key);
},

async deleteItem(key: string): Promise<void> {
try {
await EncryptedStorage.removeItem(key);
} catch (error: any) {
// There was an error on the native side
// You can find out more about this error by using the `error.code` property
console.log(error.code); // ex: -25300 (errSecItemNotFound)
Toast.show({
type: 'error',
text1: error.code,
position: 'bottom',
bottomOffset: 80,
});
}
},

async clearStorage(): Promise<void> {
try {
await EncryptedStorage.clear();
// Congrats! You've just cleared the device storage!
} catch (error: any) {
// There was an error on the native side
Toast.show({
type: 'error',
text1: error.code,
position: 'bottom',
bottomOffset: 80,
});
}
},
};
1 change: 1 addition & 0 deletions src/utils/index.ts
shreya-mishra marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dataStore'
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6238,6 +6238,11 @@ react-native-element-dropdown@^2.0.0:
dependencies:
lodash "^4.17.21"

react-native-encrypted-storage@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/react-native-encrypted-storage/-/react-native-encrypted-storage-4.0.3.tgz#2a4d65459870511e8f4ccd22f02433dab7fa5e91"
integrity sha512-0pJA4Aj2S1PIJEbU7pN/Qvf7JIJx3hFywx+i+bLHtgK0/6Zryf1V2xVsWcrD50dfiu3jY1eN2gesQ5osGxE7jA==

react-native-floating-action@^1.22.0:
version "1.22.0"
resolved "https://registry.yarnpkg.com/react-native-floating-action/-/react-native-floating-action-1.22.0.tgz#7ec476f320e16855ad4077a3a9f36511d1718a52"
Expand Down
Loading