Skip to main content
Version: Guardian v0.5.3

Provider Setup

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
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​

PropTypeDefaultDescription
logLevel'debug' | 'info' | 'warn' | 'error' | 'none''warn'SDK log verbosity. Applied on iOS. Android ignores it and logs at INFO level.
collectLocationbooleanfalseEnable GPS collection (requires permissions)
collectWifiInfobooleanfalseEnable WiFi network details (Android only)
collectSimCardInfobooleanfalseEnable SIM/carrier info (Android only)
collectCameraInfobooleanfalseEnable camera count (Android only)

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({
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?: VerifyOptions) => Promise<CollectResult>
} = useGuardian();
warning

useGuardian() must be called inside a <GuardianProvider>. Calling it outside throws an error.

Troubleshooting​

ErrorCauseFix
verification_failed with not_initialized in the message (iOS)verify() called before SDK is readyUse GuardianProvider or call initialize() at startup
useGuardian hook errorHook used outside providerWrap component tree with <GuardianProvider>
verification_failedThe request to Surt failed. A missing, malformed, or expired JWT is one cause. On Android the message contains the HTTP status.Request a new JWT from your backend for each call and pass it to verify()

verify() and collect() reject with error.code set to verification_failed, collect_failed, or sdk_error. See Error Codes for how to read the detail.