Skip to content

Commit

Permalink
Merge pull request #185 from bugsnag/PLAT-12164/secure-store-web-crash
Browse files Browse the repository at this point in the history
Prevent crashes on Web
  • Loading branch information
yousif-bugsnag committed Jun 11, 2024
2 parents 8a7a586 + d9b38cd commit 5cf7d85
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/plugin-expo-app/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Application = require('expo-application')
const Constants = require('expo-constants').default
const { AppState } = require('react-native')
const { AppState, Platform } = require('react-native')

const appStart = new Date()

Expand All @@ -19,9 +19,9 @@ module.exports = {
let bundleVersion, versionCode

if (Constants.appOwnership !== 'expo') {
if (Constants.platform.ios) {
if (Platform.OS === 'ios') {
bundleVersion = Application.nativeBuildVersion
} else if (Constants.platform.android) {
} else if (Platform.OS === 'android') {
versionCode = Application.nativeBuildVersion
}
}
Expand Down
13 changes: 11 additions & 2 deletions packages/plugin-expo-app/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ jest.mock('react-native', () => ({
AppState: {
addEventListener: jest.fn(),
currentState: 'active'
}
},
Platform: { OS: 'android' }
}))

describe('plugin: expo app', () => {
Expand Down Expand Up @@ -66,6 +67,13 @@ describe('plugin: expo app', () => {
appOwnership: null
}
}))
jest.doMock('react-native', () => ({
AppState: {
addEventListener: jest.fn(),
currentState: 'active'
},
Platform: { OS: 'ios' }
}))

const plugin = require('..')

Expand Down Expand Up @@ -109,7 +117,8 @@ describe('plugin: expo app', () => {
}))

jest.doMock('react-native', () => ({
AppState
AppState,
Platform: { OS: 'ios' }
}))

const plugin = require('..')
Expand Down
21 changes: 12 additions & 9 deletions packages/plugin-expo-device/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ module.exports = {
// get the initial orientation
updateOrientation()

const storeOptions = {
requireAuthentication: false,
keychainAccessible: SecureStore.ALWAYS_THIS_DEVICE_ONLY
}
let deviceId
if (Platform.OS === 'android' || Platform.OS === 'ios') {
const storeOptions = {
requireAuthentication: false,
keychainAccessible: SecureStore.ALWAYS_THIS_DEVICE_ONLY
}

let deviceId = SecureStore.getItem(DEVICE_ID_KEY, storeOptions)
if (!deviceId || !cuid.isCuid(deviceId)) {
deviceId = cuid()
SecureStore.setItem(DEVICE_ID_KEY, deviceId, storeOptions)
deviceId = SecureStore.getItem(DEVICE_ID_KEY, storeOptions)
if (!deviceId || !cuid.isCuid(deviceId)) {
deviceId = cuid()
SecureStore.setItem(DEVICE_ID_KEY, deviceId, storeOptions)
}
}

const device = {
Expand All @@ -47,7 +50,7 @@ module.exports = {
reactNative: rnVersion,
expoApp: Constants.expoVersion,
expoSdk: Constants.expoConfig?.sdkVersion,
androidApiLevel: Constants.platform.android ? String(Platform.Version) : undefined
androidApiLevel: Platform.OS === 'android' ? String(Platform.Version) : undefined
},
totalMemory: Device.totalMemory
}
Expand Down

0 comments on commit 5cf7d85

Please sign in to comment.