Build with React Native
Get started with Openfort in your React Native project
1. Install Required Dependencies#
Install the latest version of the Openfort React Native SDK and its required dependencies:
2. Configure Metro#
Create or update your metro.config.js
to include the necessary Node.js module shims:
_15// metro.config.js_15const { getDefaultConfig } = require('expo/metro-config');_15_15module.exports = (() => {_15 const config = getDefaultConfig(__dirname);_15_15 // Add shims for Node.js modules_15 config.resolver.extraNodeModules = {_15 crypto: require.resolve('react-native-crypto'),_15 stream: require.resolve('stream-browserify'),_15 buffer: require.resolve('buffer'),_15 };_15_15 return config;_15})();
3. Set up auth providers#
Navigate to the auth providers page on the Openfort dashboard by selecting your project and clicking Auth Providers Methods in the side bar in the players page. Select the account types you'd like users to be able to login with.
4. Get your Openfort keys#
From the Openfort Dashboard, select your desired app and navigate to the developers page. You'll need:
- Publishable Key: Safe to expose in client-side environment
- Secret Key: Must be kept secure and used only server-side
- Shield Keys: Required for non-custodial wallets
- Create Shield keys in the Shield section
- Securely store the encryption share shown in the one-time popup
- You'll get both a Publishable and Secret Shield key
5. Configure your app#
Import Polyfills#
First, import the Openfort React Native polyfills at the top of your app:
_10import "@openfort/react-native/polyfills";
Set up the WebView#
Add the Openfort Communication WebView to your app's root layout:
_11// app/_layout.tsx_11import { OpenfortCommunicationWebView } from '@openfort/react-native';_11_11export default function RootLayout() {_11 return (_11 <>_11 <OpenfortCommunicationWebView />_11 <Slot />_11 </>_11 );_11}
Initialize Openfort#
Configure the Openfort SDK with your keys:
_10import Openfort from "@openfort/react-native";_10_10const openfort = new Openfort({_10 baseConfiguration: {_10 publishableKey: "YOUR_OPENFORT_PUBLISHABLE_KEY",_10 },_10 shieldConfiguration: {_10 shieldPublishableKey: "YOUR_SHIELD_PUBLISHABLE_KEY",_10 }_10});
Because we use mmkv
storage, expo-go will not work. Use expo run:ios
or expo run:android
to run your app.
Next Steps#
Now that you've configured your app, you can use openfort
throughout to access the Openfort SDK. Check out our starter repo to see a complete integration.