UNPKG

onboardsync-react-native

Version:

Expo SDK for OnboardSync - Remote onboarding configuration platform with A/B testing

40 lines (33 loc) 1.15 kB
import * as SecureStore from 'expo-secure-store'; import * as Crypto from 'expo-crypto'; import { Constants } from '../constants'; export class DeviceIDManager { private static deviceId: string | null = null; static async getDeviceId(): Promise<string> { // Return cached value if available if (this.deviceId) { return this.deviceId; } try { // Try to get from storage const storedId = await SecureStore.getItemAsync(Constants.DEVICE_ID_KEY); if (storedId) { console.log('[OnboardSync] Retrieved device ID from storage'); this.deviceId = storedId; return storedId; } // Generate new ID if not found const newId = Crypto.randomUUID(); await SecureStore.setItemAsync(Constants.DEVICE_ID_KEY, newId); console.log('[OnboardSync] Generated new device ID'); this.deviceId = newId; return newId; } catch (error) { console.error('[OnboardSync] Error managing device ID:', error); // Fallback to a temporary ID const tempId = Crypto.randomUUID(); this.deviceId = tempId; return tempId; } } }