Guide
Riconosca i clienti autenticati in React Native
Copi uno shim, lo inietti prima che il contenuto si carichi, e risponda agli stessi quattro messaggi di identità che risponde ogni bridge nativo — una WebView, entrambe le piattaforme.
In questa pagina
Busymate AI reaches a React Native app the same way it reaches any native shell: a small bridge answers who is signed in. React Native hides both platforms' native bridges behind one WebView component, so the frozen v2 bridge installs a single shim that speaks the same wire messages on either OS.
Current: Sign-in and identity, Setup C.
1. Copy the bridge files
Copy https://busymate.ai/sdk/v2/2.0.0/react-native/busymateBridge.js and https://busymate.ai/sdk/v2/2.0.0/core/busymateBridgeCore.js into your app. Create the bridge with createBusymateBridge({ assistant, appId, account, mint }): account returns your user id or null, and mint calls your own authenticated API with the request's nonce.
2. Inject before content loads, not after
Pass bridge.injectedJavaScriptBeforeContentLoaded to your WebView, give it ref={bridge.ref}, and set onMessage={bridge.onMessage}. Load the hosted chat URL from Console › Integration with channel=android or channel=ios.
Use injectedJavaScriptBeforeContentLoaded, never injectedJavaScript: the latter runs after load, so the very first identity ask can arrive before your bridge exists and gets no answer at all.
3. Tell the bridge when the user changes
Your mint calls your authenticated API on every ask, never a cached value. Call bridge.accountChanged() on login, token rotation, account switch and logout: it is the one signal, and account returns null once the user is signed out.
4. Try it with a fake sign-in first
Wire account to a toggle before your real auth store. Confirm the widget goes anonymous, then identified, then anonymous again as you flip it, with no reload.
Verify
- Signed out, open the screen: the mate runs an anonymous, guest session.
- Sign in inside your app, without reloading the WebView, and call
accountChanged(): the same thread becomes identified. - Background the app past the token's lifetime, then foreground it: the mate re-asks and gets a fresh answer, not a refused stale one.
- Sign out and reopen the screen: the previous customer's history is gone, not merely hidden.
- Run the Identity check against
channel=android; React Native answers through the same wire shape the checker already grades.
Next steps
- Recognize signed-in customers — the four obligations this bridge answers.
- Native SDKs — the native bridge this shim mirrors.
- Fix a signed-in customer who shows as a guest — symptom-first fixes when a cell fails.
Domande
Do I need a separate integration for iOS builds of the same app?
No. The
WebViewcomponent and this shim are the same on both platforms; only your native project's build configuration differs, not this bridge.Why can't I use injectedJavaScript — it is simpler to reason about?
It runs once the page has already loaded, which is after the mate's first identity ask. A handler installed that late misses the one ask that matters most, the first one.
Does the shim work with Expo's managed WebView?
Any component built on
react-native-webviewaccepts the same two props (injectedJavaScriptBeforeContentLoaded,onMessage), so the bridge asks nothing extra of your bundler or build tool.What if my app never installs the shim?
The mate still runs, anonymously. A missing bridge is a supported, guest state — never a broken chat — until you wire identity in.