A bare React Native example demonstrating how to use Firebase Authentication as a custom authentication provider with MetaMask Embedded Wallets (Web3Auth). The user signs in through Firebase (anonymous, email, or social) and receives a deterministic Ethereum wallet.
- Setting up a Custom Connection on the Web3Auth Dashboard backed by Firebase
- Using
@react-native-firebase/authto obtain a Firebase ID token - Passing the Firebase JWT to
@web3auth/react-native-sdkvialoginConfig - Connecting the built-in EVM provider and making Ethereum calls with
ethers.js
- The user taps Login.
- Firebase Authentication signs the user in (anonymous sign-in in this example — swap for email/password or any Firebase provider).
- Firebase issues a JWT (
idToken). - The JWT is passed to Web3Auth, which validates it against the Custom Connection configured on the dashboard.
- Web3Auth reconstructs the user's key shares and returns an EVM provider.
- React Native
0.74.x(bare workflow) @web3auth/react-native-sdk^8.0.0@web3auth/ethereum-provider^9.3.0@react-native-firebase/app+@react-native-firebase/authethers^6.xreact-native-encrypted-storage@toruslabs/react-native-web-browser
- Node.js
>=18 - React Native development environment — React Native CLI Quickstart
- A Firebase Project with Authentication enabled
- A Web3Auth Dashboard project
- Create a project in the Firebase Console.
- Enable Authentication and the sign-in methods you want (e.g. Anonymous, Email/Password, Google).
- Download
google-services.json(Android) andGoogleService-Info.plist(iOS) and place them in the correct native folders. - Note your Project ID and the Firebase JWKS endpoint:
https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com
- Go to dashboard.web3auth.io and open your project.
- Under Connections, create a Custom Connection:
- Type: Custom JWT
- JWKS endpoint:
https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com - JWT validation fields:
iss=https://securetoken.google.com/YOUR_FIREBASE_PROJECT_ID,aud=YOUR_FIREBASE_PROJECT_ID - User identifier field:
sub
- Note the Connection ID (formerly called verifier name).
- Under Allowed Origins, add your app's redirect URL:
web3authrnbarefirebase://auth
git clone https://github.com/Web3Auth/web3auth-react-native-examples.git
cd web3auth-react-native-examples/rn-bare-firebase-example
npm installcd ios && pod install && cd ..In App.tsx, update:
const clientId = "YOUR_WEB3AUTH_CLIENT_ID"; // from Web3Auth Dashboard
const web3auth = new Web3Auth(WebBrowser, EncryptedStorage, {
clientId,
network: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET, // SAPPHIRE_MAINNET for production
redirectUrl: "web3authrnbarefirebase://auth",
loginConfig: {
jwt: {
verifier: "YOUR_CONNECTION_ID", // Connection ID from Web3Auth Dashboard
typeOfLogin: "jwt",
clientId,
},
},
privateKeyProvider: ethereumPrivateKeyProvider,
});npm start # start Metro
npm run ios # iOS
npm run android # Android// 1. Sign in with Firebase
const res = await firebaseAuth().signInAnonymously();
const firebaseIdToken = await res.user.getIdToken(true);
// 2. Pass the Firebase JWT to Web3Auth
await web3auth.login({
loginProvider: LOGIN_PROVIDER.JWT,
extraLoginOptions: {
id_token: firebaseIdToken,
verifierIdField: "sub",
},
});const ethersProvider = new ethers.BrowserProvider(web3auth.provider!);
const signer = await ethersProvider.getSigner();
const address = await signer.getAddress();
const balance = await ethersProvider.getBalance(address);Custom Connection — Configured on the Web3Auth Dashboard with the Firebase JWKS endpoint and validation rules. Web3Auth uses this to verify that the JWT was issued by your Firebase project.
getIdToken(true) — Pass true to force-refresh the token. Web3Auth requires the JWT's iat claim to be within 60 seconds of the current time, so always request a fresh token immediately before calling web3auth.login().
Deterministic wallet — Same Firebase user (sub) + same Connection ID + same Client ID + same network = same wallet address every time.
JWT expired / iat mismatch
- Call
getIdToken(true)to get a fresh token immediately beforeweb3auth.login(). Do not cache the token.
Verifier not found error
- The
verifierfield inloginConfigmust exactly match the Connection ID in your Web3Auth Dashboard (case-sensitive).
Firebase native module not found
- Ensure
google-services.json(Android) andGoogleService-Info.plist(iOS) are placed correctly and you ranpod installafter adding them.
Metro polyfill errors
- MetaMask Embedded Wallets Docs
- React Native SDK Reference
- React Native Firebase Docs
- Dashboard
- Community (Builder Hub)
MIT — see LICENSE.