Pular para o conteúdo principal
Versão: Guardian v0.3.1

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

PropTypeDefaultDescription
environment'production' | 'sandbox''production'Backend environment
logLevel'debug' | 'info' | 'warn' | 'error' | 'none''warn'SDK log verbosity
collectLocationbooleanfalseEnable GPS collection (requires permissions)
collectWifiInfobooleanfalseEnable WiFi network details
collectSimCardInfobooleanfalseEnable SIM/carrier info (Android only)
collectCameraInfobooleanfalseEnable 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

ErrorCauseFix
not_initializedverify() called before SDK is readyUse GuardianProvider or call initialize() at startup
useGuardian hook errorHook used outside providerWrap component tree with <GuardianProvider>
invalid_jwtJWT missing, malformed, or rejectedEnsure your backend mints a fresh JWT per call and passes it to verify()