Skip to main content

Quickstart: Implementing Particle Auth within applications built with React Native

Particle Auth, the primary SDK driving standalone social logins, has native support for React Native; integration only takes a few steps. This document will go through the step-by-step process of configuring, initializing, and using Particle Auth with React Native.
For complete documentation covering the implementation of Particle Auth on React Native in more depth, head over to the React Native SDK reference.

1

Installing Particle Auth

Getting started, you’ll need to install @particle-network/rn-auth-core alongside @particle-network/rn-base.To do this, execute the command(s) below.
Terminal
2

Configuring Particle Auth

Once installed, you’re ready to begin configuring Particle Auth.To start, you’ll need to retrieve three key values from the Particle dashboard: your project ID, client key, and app ID. These are used to authenticate your instance of Particle Auth and connect your project to the dashboard;.To retrieve these keys, follow the steps outlined below:
Sign up or Log in into the Particle dashboard
Login into Particle.
Create Particle project.
Create iOS app.
Find app's credentials.
For more information on the Particle dashboard, take a look at the dashboard quickstart.

Android

If you’re planning on using Android for your React Native application, ensure you meet the following prerequisites (otherwise, expect compatibility issues):

Prerequisites

  • minSdkVersion 23 or higher.
  • compileSdkVersion, targetSdkVersion 34 or higher.
  • JavaVersion 17.
  • Jetpack (AndroidX).
  • Android Gradle Plugin Version: 8.5.1 or higher.
  • Gradle Version: 8.9 or higher. (before react-native:0.75.2, use 8.8)
Once you’ve made sure your project meets these requirements, you’ll need to move on and define the aforementioned configuration values (your project ID, client key, and app ID) within your build.grade file (which is generally found at ${project name}/android/app/build.gradle).Specifically, within build.gradle, you’ll need to set four different values:
  1. dataBinding, this should be enabled with enabled = true.
  2. manifestPlaceholders["PN_PROJECT_ID"], the project ID previously retrieved from the Particle dashboard.
  3. manifestPlaceholders["PN_PROJECT_CLIENT_KEY"], the client key previously retrieved from the Particle dashboard.
  4. manifestPlaceholders["PN_APP_ID"], the app ID previously retrieved from the Particle dashboard.
build.gradle

iOS

Alternatively, if you plan to use iOS for your React Native application, the underlying setup process differs slightly. Before diving in, you’ll need to ensure that your project meets the following requirements:
  • Xcode 15.0 or later.
  • iOS 14 or later.
With these requirements set, you’ll need to open an exported iOS project and navigate to ios/{project name}.xcworkspace.
1

Configuring ParticleNetwork-Info.plist

At the root of your Xcode project, create a new file, ParticleNetwork-Info.plist. Ensure this is marked under “Target Membership.”From here, with a fresh ParticleNetwork-Info.plist file, go ahead and fill it in with the previously retrieved project keys (from the Particle dashboard):
ParticleNetwork-Info.plist
2

Configuring Info.plist: Face ID

Additionally, to enable Face ID (privacy setting) to your app, head over to (or create) the Info.plist file and include the following snippet:
Info.plist
3

Configuring your Podfile

Finally, you’ll need to edit your Podfile to align with the snippet below; this is required for all iOS projects that leverage Particle Auth Core.

Specific note for using Expo.

If you’re working with Expo, your Podfile needs additional editing to ensure compatibility with Particle Auth Core, as below:

You can reference this Podfile.

3

Initializing Particle Auth

Having now installed and configured Particle Auth based on the platform you’re using, you’ll need to initialize the SDK.Particle Auth can be initialized by first setting your project ID and client key through defining ParticleInfo.projectId and ParticleInfo.clientKey.After doing so, simply call the init method on particleBase. This takes the following parameters:
  • chainInfo, representing the primary chain you intend to use (for example, ChainInfo.Ethereum, chainInfo.Polygon).
  • env, affecting the information logged within your environment (Env.dev, Env.production, or Env.staging).
The snippet below is an example of this.
4

Facilitating social login

You’re ready to facilitate social login and interacting with the resulting account.As shown below, you’ll need to call particleAuthCore.connect to initiate social login, passing in the specific login type you’d like the user to onboard through (.Google, .Twitter, .Discord, etc.) alongside, if applicable, the type of account prompt used by the OAuth provider (.SelectAccount, .Consent, .None).
When a user logs in for the first time, if there is no account, we will create one. Based on the current chainInfo, a new address will be generated. For example, if the current chain is EVM-compatible, only an EVM address will be generated; if it’s the Solana chain, only a Solana address will be generated. If you want to obtain both addresses, you can use ParticleAuthCore.switchChain to switch chains, and after waiting for 2 seconds, a new address for the selected chain will be generated for you.

Examples of Utilization

Retrieve User Information

With a user logged in, you’ll be able to retrieve information about their account (such as their address, or specific details regarding the social login mechanism they used) through methods such as evm.getAddress and particleAuthCore.getUserInfo (getUserInfo returns an object with numerous points of information; to learn more, head over to its API reference). The following snippet is an example of retrieving a user’s address on both EVM and Solana alongside pulling their broader account information.

Send a Transaction

Now, as a final example, you can send a transaction, such as burning 0.000000001 ETH. To do this, you’ll need to construct a transaction with EvmService.createTransaction using standard parameters such as evmAddress (the sender), data, value, and receiverAddress, Upon construction, the transaction can be sent through evm.sendTransaction; once the user signs/confirms, it’ll be pushed to the network; an example of this is shown below.
Take a look at the complete demo project here.