{"id":26476895,"url":"https://github.com/juliandramirez/react-native-user-identity","last_synced_at":"2025-07-25T13:38:01.909Z","repository":{"id":34645910,"uuid":"181193131","full_name":"juliandramirez/react-native-user-identity","owner":"juliandramirez","description":"Get the user id configured for the device (iCloud recordID for iOS, email of a device account for android)","archived":false,"fork":false,"pushed_at":"2023-07-18T21:22:54.000Z","size":27478,"stargazers_count":34,"open_issues_count":3,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-18T13:15:32.632Z","etag":null,"topics":["android","firebase-auth","ios","npm-package","react-native","sign-in-with-apple"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juliandramirez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-13T15:44:22.000Z","updated_at":"2025-03-06T05:58:59.000Z","dependencies_parsed_at":"2024-06-18T22:55:04.463Z","dependency_job_id":null,"html_url":"https://github.com/juliandramirez/react-native-user-identity","commit_stats":{"total_commits":25,"total_committers":4,"mean_commits":6.25,"dds":"0.16000000000000003","last_synced_commit":"7551c21104ed3736e4fdadfd592cf426ba88039d"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliandramirez%2Freact-native-user-identity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliandramirez%2Freact-native-user-identity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliandramirez%2Freact-native-user-identity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliandramirez%2Freact-native-user-identity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliandramirez","download_url":"https://codeload.github.com/juliandramirez/react-native-user-identity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244525611,"owners_count":20466548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","firebase-auth","ios","npm-package","react-native","sign-in-with-apple"],"created_at":"2025-03-20T00:08:33.757Z","updated_at":"2025-03-20T00:08:34.272Z","avatar_url":"https://github.com/juliandramirez.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# react-native-user-identity\n\n![npm](https://img.shields.io/npm/v/react-native-user-identity.svg) ![npm](https://img.shields.io/npm/dt/react-native-user-identity) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-native-user-identity.svg) ![Supports Android and iOS](https://img.shields.io/badge/platforms-android%20|%20ios-lightgrey.svg) ![GitHub](https://img.shields.io/github/license/juliandramirez/react-native-user-identity.svg) ![Codecov](https://img.shields.io/codecov/c/github/juliandramirez/react-native-user-identity.svg)\n\nGet the user id configured for the device (iCloud recordID for iOS, email of a device account for android)\n\n## Why should you use this?\n\nWhen implementing a mobile application you want to provide your users as much functionality as you can without having them sign up. After all, [Every Step Costs You 20% of Users](https://medium.com/gabor/every-step-costs-you-20-of-users-b613a804c329). \u003cbr\u003e\nSign up may very well be the step where most of your potential users are lost.\n\nNow imagine you could get a unique identifier that worked across all of the devices of the user.\nYou could even have in-app purchases that are shared across devices **without having to sign-up**.\n\nThis library aims to provide all of the above in the simplest way possible:\n* For ios it uses the record name of CloudKit so it uniquely identifies an ios user. It's difficult to imagine an apple user that does not have an iCloud account configured in each of their devices.\n* For android it presents to the user a list of all the accounts configured in the device to choose from.\u003cbr\u003eIt presents the list of google accounts configured (...@gmail, ...@corporateGmail) since it's one of the first steps of configuring an android device nowadays.\n\n\u003cbr\u003e\nNote: If you are already using firebase authentication see the FAQ for instructions on how to upgrade its anonymous authentication\n\u003cbr\u003e\u003cbr\u003e\nNote: If you are considering using Sign In with Apple see the FAQ section first\n\n## Installation\n**1. Install the library**\n```\nyarn add react-native-user-identity\n```\n**2. Run pod install**\n```\ncd ios\npod install\n```\n**3. (OPTIONAL STEP: REQUIRED FOR OLD DEPENDENCY VERSIONS AND SDKs) Configure swift support for your iOS project** \n\nThis configures your iOS project to use the module correctly since the library contains swift code (see the [official react native documentation](https://reactnative.dev/docs/native-modules-ios.html#exporting-swift) for more information)\n\n**Note:** If your iOS project is alredy using swift files and you have a bridging header you may skip this step.\n\na. Create a swift file with any name in the root of your project:\n\n![alt text](https://raw.githubusercontent.com/juliandramirez/react-native-user-identity/master/docs/img/create-swift.png)\n\nb. Select \"Create Bridging Header\" when Xcode asks for it:\n\n![alt text](https://raw.githubusercontent.com/juliandramirez/react-native-user-identity/master/docs/img/create-header.png)\n\n**4. Build the project**\n\nYou should be able to build the project now. \u003cbr\u003e\n**Note:** The package functionality will not work until you follow the steps of the next section\n\n**Note 2:** If you are having trouble building your project after executing the example try opening XCode preferences, select the \"Locations\" tab and set DerivedData to be a relative folder.\n\n## Configuration\n\n### Android\n\nNothing to configure.\n\n### iOS \n(Screenshots taken with Xcode 11.x)\n\n1. Make sure your app has a unique bundle identifier and does not show any errors in the Signing section (requires an apple development account):\n\n![alt text](https://raw.githubusercontent.com/juliandramirez/react-native-user-identity/master/docs/img/xcode-signing.png)\n\n2. Add the iCloud capability for the project:\n\n![alt text](https://raw.githubusercontent.com/juliandramirez/react-native-user-identity/master/docs/img/xcode-cloudkit.png)\n\n3. Enable the CloudKit option of the iCloud capability\n\n4. (OPTIONAL STEP: REQUIRED FOR OLD IDE CONFIGURATIONS) Add a container and name it **exactly as the bundle identifier of the application**:\n\n![alt text](https://raw.githubusercontent.com/juliandramirez/react-native-user-identity/master/docs/img/xcode-cloudcontainer.png)\n\n\n**Verify all of the following:**\n* The format of the container name is iCloud.$(PRODUCT_BUNDLE_IDENTIFIER)\n* Press the \"Cloudkit Dashboard\" button, sign in with your developer account. You should see your newly created container in the list of containers (If you don't see it go to XCode and press the refresh button until it does). Verify that there is no error when selecting your container in the web dashboard. \u003cbr\u003e If there is an error just wait and keep trying until the container is created succesfully (web dashboard/Xcode 11 seems to be buggy here since creating an iCloud container actually takes a couple of minutes).\n* Go back to XCode and verify that the container name is not highlighted in red after you press the refresh option\n\n![alt text](https://raw.githubusercontent.com/juliandramirez/react-native-user-identity/master/docs/img/xcode-icloudverified.png)\n\n## Usage\n\n* There is only one public function available called ***getUserId***\n* The function is marked as ***async***\n* The resolved value is ***null*** when the user cancels the UI flow\n* On **ios** the function will throw ICLOUD_ACCESS_ERROR when there is no icloud account configured\n  \n```javascript\nimport RNUserIdentity, { ICLOUD_ACCESS_ERROR } from 'react-native-user-identity'\n\nfetchUserIdentity = async () =\u003e {\n\ttry {\n\t\tconst result = await RNUserIdentity.getUserId()\n\t\tif (result === null) {\n\t\t\talert('User canceled UI flow')\n\t\t} \n\t} catch(error) {\n\t\tif (error === ICLOUD_ACCESS_ERROR) {\n\t\t\talert('Please set up an iCloud account in settings')\n\t\t}\n\t}\n}\n```\n\n### IOS user confirmation (only if you want user intervention)\n\nOn iOS fetching the id **does not require user intervention**. However, it might be useful in some instances to have the user confirm the action.\u003cbr\u003e\nYou may send a *truthy* value for the **iosUserConfirmation** parameter for this to happen.\n\nThe following code:\n\n```javascript\nRNUserIdentity.getUserId({\n\t\tiosUserConfirmation: true\n})\n```\n\nPresents this dialog:\n\n![alt text](https://raw.githubusercontent.com/juliandramirez/react-native-user-identity/master/docs/img/ios-user-confirmation.png)\n\nThe resolved value will be ***null*** if the user dismisses the dialog\n\u003cbr\u003e\u003cbr\u003e\nYou can also configure the text shown to the user:\n\n```javascript\nRNUserIdentity.getUserId({\n\t\tiosUserConfirmation: {\n\t\t\ttitle: 'Confirm sign in',\n\t\t\tmessage: 'Sign in requires user confirmation',\n\t\t\tsignInButtonText: 'Confirm',\n\t\t\tcancelButtonText: 'Back'\n\t\t}\n})\n```\n\n### Android account chooser options\n\nThere is an optional parameter you can send:\n* **androidAccountSelectionMessage**: The text to display in the account chooser modal in android. By default there is no message configured.\n\nThe following code:\n\n```javascript\nRNUserIdentity.getUserId({\n\t\tandroidAccountSelectionMessage: 'Choose an account for testing:'\n})\n```\n\nPresents this modal (the modal styles are OS dependant):\n\n![alt text](https://raw.githubusercontent.com/juliandramirez/react-native-user-identity/master/docs/img/android-account-chooser.png)\n\n### Running the example project\n\nUse yarn to install the dependencies. Npm installs local dependencies using symbolic links and the react native packager does not support this.\n\n## FAQ\n\n### Why can't we get the iCloud email and instead we get this long obfuscated string?\nThe CloudKit framework prevents applications from accesing the user email for privacy purposes.\n\n### How is this different from Sign In with apple on iOS?\nSign in with Apple requires the user to complete a full sign in flow.\u003cbr\u003e\nThe point of using this package is to skip entirely this flow so your users can directly start using your application\n\n### I can not make this work on iOS...\nMake sure you followed all of the steps in the installation and configuration section and pay attention to the verification note at the end of the configuration section\n\n### Is there another option for having a user id without asking users to sign up?\nYou could use the same principle behind [Firebase anonymous authentication](https://firebase.google.com/docs/auth/web/anonymous-auth) but most likely you will run into the same limitations: Identities are associated to app installations (or devices in the best case scenario).\u003cbr\u003e\n**Once a user uninstalls the app, signs out or changes devices the user identity is lost.**\n\n### How to integrate with firebase authentication?\nIf you are already using firebase authentication you want to incorporate react-native-user-identity as another option for the user to sign in (or maybe you just want to replace anonymous authentication).\u003cbr\u003e\u003cbr\u003e\nYou should then:\n1. Create a custom token with the firebase admin sdk.\u003cbr\u003e \nCustom tokens should be created on the server side of your application, as they should be signed and secured. See [Creating custom tokens for firebase](https://firebase.google.com/docs/auth/admin/create-custom-tokens).\u003cbr\u003e\nIf you are going serverless you can easily deploy the following cloud function to firebase:\n```javascript\nconst functions = require('firebase-functions')\nconst admin = require('firebase-admin')\n\nadmin.initializeApp()\n\nexports.tokenFromUID = functions.https.onCall( async (data, context) =\u003e {    \n    const { uid } = data\n\n    try {\n        return await admin.auth().createCustomToken(uid)\n    } catch(error) {\n        console.log('Error creating custom token: ', error)\n        throw new functions.https.HttpsError('internal', error ? error.message : '')\n    }\n})\n```\nWith this cloud function you also need to configure permissions for your firebase instance. See [this section of the firebase documentation](https://firebase.google.com/docs/auth/admin/create-custom-tokens#troubleshooting) for details\n\u003cbr\u003e\u003cbr\u003e\n\n2. Sign in with the custom token on your app\u003cbr\u003e Assuming you are using [rnfirebase](https://rnfirebase.io/):\n\nReplace this:\n```javascript\nimport auth from '@react-native-firebase/auth'\n\nconst userCredential = await auth().signInAnonymously()\n```\nWith this:\n```javascript\nimport auth from '@react-native-firebase/auth'\nimport functions from '@react-native-firebase/functions'\nimport RNUserIdentity from 'react-native-user-identity'\n\n// get uid for user...\nconst uid = await RNUserIdentity.getUserId()\nif (uid != null) {\n\t// Server call (a firebase cloud function in this case)\n\tconst tokenResponse = await functions().httpsCallable('tokenFromUID')({ uid })\n\tconst userCredential = await auth().signInWithCustomToken(tokenResponse.data)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliandramirez%2Freact-native-user-identity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliandramirez%2Freact-native-user-identity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliandramirez%2Freact-native-user-identity/lists"}