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
environment="production"
collectLocation={true}
>
<Navigation />
</GuardianProvider>
);
}
The SDK does not hold an API key. Customer and transaction context come from a short-lived JWT that your backend mints. See Verify Transactions for details.
Provider Props
| Prop | Type | Default | Description |
|---|---|---|---|
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({
environment: 'production',
logLevel: 'warn',
collectLocation: true,
});
useGuardian Hook
const {
isInitialized, // boolean - true after SDK is ready
verify, // (jwt: string, options?: VerifyOptions) => Promise<VerificationResult>
collect, // (jwt?: string, options?: CollectOptions) => Promise<CollectResult>
} = useGuardian();
aviso
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_jwt | JWT missing, malformed, or rejected | Ensure your backend mints a fresh JWT per call and passes it to verify() |