Provider Setup
Option A: Provider + Hook (Recommended)
Wrap your app root with GuardianProvider. This initializes the SDK and exposes it to all child components via the useGuardian hook.
App.tsx
import { GuardianProvider } from '@surtai/guardian-rn';
export default function App() {
return (
<GuardianProvider
apiKey="YOUR_API_KEY"
environment="production"
collectLocation={true}
>
<Navigation />
</GuardianProvider>
);
}
Provider Props
| Prop | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Your Surt API key (API key) |
environment | 'production' | 'sandbox' | 'production' | Backend environment |
logLevel | 'debug' | 'info' | 'warn' | 'error' | 'none' | 'warn' | SDK log verbosity |
collectLocation | boolean | false | Enable GPS collection (requires permissions) |
collectWifiInfo | boolean | false | Enable WiFi network details |
collectSimCardInfo | boolean | false | Enable SIM/carrier info (Android only) |
collectCameraInfo | boolean | false | Enable camera info |
Option B: Imperative API
If you prefer not to use React context, call initialize() directly at app startup:
index.ts
import { GuardianSDK } from '@surtai/guardian-rn';
GuardianSDK.initialize('API keyxxx', {
environment: 'production',
logLevel: 'warn',
collectLocation: true,
});
useGuardian Hook
const {
isInitialized, // boolean - true after SDK is ready
verify, // (type, name?, options?) => Promise<VerificationResult>
setCustomer, // (id, name?, email?) => void
clearCustomer, // () => void
} = useGuardian();
warning
useGuardian() must be called inside a <GuardianProvider>. Calling it outside throws an error.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
not_initialized | verify() called before SDK is ready | Use GuardianProvider or call initialize() at startup |
useGuardian hook error | Hook used outside provider | Wrap component tree with <GuardianProvider> |
invalid_api_key | Wrong or expired API key | Verify your API key key with Surt |