37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
|
const KEYS = {
|
|
TOKEN: '@token',
|
|
PARTNER_ID: '@partner_id',
|
|
HAS_COMPLETED_ONBOARDING: '@has_completed_onboarding',
|
|
};
|
|
|
|
class StorageService {
|
|
async saveToken(token: string, partnerId: string): Promise<void> {
|
|
await AsyncStorage.setItem(KEYS.TOKEN, token);
|
|
await AsyncStorage.setItem(KEYS.PARTNER_ID, partnerId);
|
|
}
|
|
|
|
async getToken(): Promise<{ token: string | null; partnerId: string | null }> {
|
|
const token = await AsyncStorage.getItem(KEYS.TOKEN);
|
|
const partnerId = await AsyncStorage.getItem(KEYS.PARTNER_ID);
|
|
return { token, partnerId };
|
|
}
|
|
|
|
async removeToken(): Promise<void> {
|
|
await AsyncStorage.removeItem(KEYS.TOKEN);
|
|
await AsyncStorage.removeItem(KEYS.PARTNER_ID);
|
|
}
|
|
|
|
async setOnboardingComplete(complete: boolean): Promise<void> {
|
|
await AsyncStorage.setItem(KEYS.HAS_COMPLETED_ONBOARDING, JSON.stringify(complete));
|
|
}
|
|
|
|
async getOnboardingComplete(): Promise<boolean> {
|
|
const val = await AsyncStorage.getItem(KEYS.HAS_COMPLETED_ONBOARDING);
|
|
return val ? JSON.parse(val) : false;
|
|
}
|
|
}
|
|
|
|
export const storageService = new StorageService();
|