Enforce RBAC permissions in your application’s frontend using the Stytch Vanilla JS SDK
import { StytchB2BClient } from '@stytch/vanilla-js/b2b'; const stytch = new StytchB2BClient('public-token-test-b8c84de4-7d58-4ffc-9341-432b56596862'); const editButton = document.getElementById('edit-button'); // Check permissions both before taking actions const editDocument = async () => { const { isAuthorized } = await stytch.rbac.isAuthorized({ resourceId: 'documents', action: 'edit' }); if (!isAuthorized) { throw new Error('You do not have permission to edit documents'); } proceedWithEdit(); }; // And to hide or disable UI elements const checkPermissions = async () => { const { isAuthorized } = await stytch.rbac.isAuthorized({ resourceId: 'documents', action: 'edit' }); editButton.disabled = !isAuthorized; }; editButton.addEventListener('click', editDocument); checkPermissions();