juliandramirez / react-native-user-identity

Get the user id configured for the device (iCloud recordID for iOS, email of a device account for android)
Apache License 2.0
31 stars 12 forks source link

TypeError: Cannot read properties of undefined (reading 'getUserId') #20

Closed danhab99 closed 2 years ago

danhab99 commented 2 years ago

I can't access the getUserId function.

import RNUserIdentity, { ICLOUD_ACCESS_ERROR } from 'react-native-user-identity'
const checkAccount = async () => {
    try {
        const result = await RNUserIdentity.getUserId()
        // const result = await RNUserIdentity.default.getUserId()
        // const result = await RNUserIdentity.getUserIdentity()
        if (result === null) {
            onPressed?.(false)
            if (alert) {
                Alert.alert(
                    "iCloud Error",
                    "You have to enable iCloud to add your ID to your Apple Wallet"
                )
            }
        }
        else {
            onPressed?.(true)
        }
    } catch (error) {
        console.error(error)
        if (error === ICLOUD_ACCESS_ERROR) {
            if (alert) {
                Alert.alert(
                    "iCloudError",
                    "Unable to access iCloud"
                )
            }
            return onPressed?.(false, error)
        }

        throw error
    }
}
danhab99 commented 2 years ago

Figured it out. Use this import line:

import * as RNUserIdentity from 'react-native-user-identity'

And this call to get the user's iCloud ID

const result = await RNUserIdentity.default.getUserId()