49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { ROLE, UID } from "@/constants";
|
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
|
|
export async function setStorageItem(
|
|
key: string,
|
|
value: string
|
|
): Promise<void> {
|
|
try {
|
|
await AsyncStorage.setItem(key, value);
|
|
} catch (error) {
|
|
console.error("Error setting storage item:", error);
|
|
}
|
|
}
|
|
|
|
export async function getStorageItem(key: string): Promise<string | null> {
|
|
try {
|
|
const value = await AsyncStorage.getItem(key);
|
|
return value;
|
|
} catch (error) {
|
|
console.error("Error getting storage item:", error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function removeStorageItem(key: string): Promise<void> {
|
|
try {
|
|
await AsyncStorage.removeItem(key);
|
|
} catch (error) {
|
|
console.error("Error removing storage item:", error);
|
|
}
|
|
}
|
|
|
|
export async function clearUserStorage() {
|
|
try {
|
|
await AsyncStorage.removeItem(UID);
|
|
await AsyncStorage.removeItem(ROLE);
|
|
} catch (error) {
|
|
console.error("Error with clear user Storage: ", error);
|
|
}
|
|
}
|
|
export async function addUserStorage(userId: string, role: string) {
|
|
try {
|
|
setStorageItem(UID, userId);
|
|
setStorageItem(ROLE, role);
|
|
} catch (error) {
|
|
console.error("Error with set user Storage: ", error);
|
|
}
|
|
}
|