Skip to content

Commit d127a85

Browse files
make expo-crypto optional (#292)
1 parent 8e6101c commit d127a85

File tree

4 files changed

+353
-14
lines changed

4 files changed

+353
-14
lines changed

.vscode/settings.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

javascript/mixpanel-persistent.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
import { AsyncStorageAdapter } from "./mixpanel-storage";
1313
import uuid from "uuid";
1414
import { MixpanelLogger } from "mixpanel-react-native/javascript/mixpanel-logger";
15-
import { randomUUID } from "expo-crypto";
1615

1716
export class MixpanelPersistent {
1817
static instance;
@@ -67,11 +66,16 @@ export class MixpanelPersistent {
6766
this._identity[token].deviceId = storageToken;
6867

6968
if (!this._identity[token].deviceId) {
69+
let newDeviceId;
7070
try {
71-
this._identity[token].deviceId = randomUUID();
71+
// Try to use expo-crypto if available
72+
const expoCrypto = require("expo-crypto");
73+
newDeviceId = expoCrypto.randomUUID();
7274
} catch (e) {
73-
this._identity[token].deviceId = uuid.v4();
75+
// Fallback to uuid.v4() if expo-crypto is not available
76+
newDeviceId = uuid.v4();
7477
}
78+
this._identity[token].deviceId = newDeviceId;
7579
await this.storageAdapter.setItem(
7680
getDeviceIdKey(token),
7781
this._identity[token].deviceId

0 commit comments

Comments
 (0)