forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import uuid from 'react-native-uuid'
2import AsyncStorage from '@react-native-async-storage/async-storage'
3
4import {device} from '#/storage'
5
6const LEGACY_STABLE_ID = 'STATSIG_LOCAL_STORAGE_STABLE_ID'
7
8export async function getAndMigrateDeviceId() {
9 const migrated = getDeviceId()
10 if (migrated) return migrated
11 const id = (await AsyncStorage.getItem(LEGACY_STABLE_ID)) || uuid.v4()
12 device.set(['deviceId'], id)
13 return id
14}
15
16export function getDeviceId() {
17 return device.get(['deviceId'])
18}
19
20export function getDeviceIdOrThrow() {
21 const id = device.get(['deviceId'])
22 if (!id) {
23 throw new Error(`deviceId is not set, call getAndMigrateDeviceId first`)
24 }
25 return id
26}