This is an standard Expo project created with create-expo-app. Added to this is a reference implementation of calling the checkResources call on an ePDP from Cerbos Hub which is cached locally.
Unfortunately, React Native does not have native support for WebAssembly so in order to use this a react-native-webview is created and the ePDP is loaded into it. Expo takes care of the bundling this local HTML file with the correct SDK implemeented. The CerbosProvider create a context which handles marshalling messages between the RN app and the webview. It also exposed the onDecision callback for capturing the decision logs.
Offline support is handled via caching the latest retrieved ePDP stored on device in async storage. By default a check will be made every 5 minutes for a new version, but the app will continue to serve the last avaliable local version should a network connection be unavailable.
An example call to the ePDP using the useCerbos hook requires passing in the principal, resources and actions to check and then the response. More details can be found in the @cerbos/embedded repo.
const { checkResources, isLoaded } = useCerbos(); // Access Cerbos context
const [result, setResult] = useState<CheckResourcesResponse | null>(null);
// Function to check permissions call when needed
const checkAccess = async () => {
try {
const result = await checkResources({
principal: {
id: "alice",
roles: ["USER"],
attr: { department: "IT" },
},
resources: [
{
resource: {
kind: "resource",
id: "doc1",
attr: { ownerId: "sally", status: "published" },
},
actions: ["view"],
},
],
});
console.log("[App] Auth check result:", JSON.stringify(result));
setResult(result);
} catch (err) {
console.error("[App] Auth check failed:", err);
setResult(null);
}
};Every React Native implementation has its own quirks, so this reference project should be adapted to best fit into your application - please get in touch with us for any questions or additional use cases.
-
Install dependencies
npm install
-
Update
./app/_layout.tsxwith the URL of the Cerbos ePDP WASM file - this can be fouund in the Decsion Points section of your Cerbos Hub account under the Embedded tab. It will begin withhttps://lite.cerbos.cloud/bundle?workspace=... -
Start the app
npx expo start
- Expose the decision audit logs generated by the ePDP back to the application
- Implement the
checkResourcehelper function to ease implementation. - Investigate the best way to do E2E testing with simulators