@ductape/react
v0.0.1
Published
React hooks and components for Ductape
Downloads
101
Maintainers
Readme
@ductape/react
React hooks and components for Ductape: useActionRun, useDatabaseQuery, useBrokerPublish, useMutation, and more.
Installation
npm install @ductape/react @ductape/client reactUsage
Wrap your app with DuctapeProvider and use the hooks. When using a publishable key:
Include
sessionin request params. Every hook that triggers a Ductape request (e.g.useActionRun,useDatabaseQuery,useMutation,useBrokerPublish) must receive a session in the options/payload. The session token must be issued by your backend (e.g. after user login). The proxy rejects requests without a validsession.const sessionToken = useSessionFromYourBackend(); // your auth state const { mutate: runAction } = useActionRun(); runAction({ app: 'ductape:paystack', action: 'list_countries', input: { 'headers:Authorization': `Bearer ${key}` }, session: sessionToken, // required when using publishable key }); const { data } = useDatabaseQuery( ['orders'], { table: 'orders', database: 'mongo-db', limit: 10, session: sessionToken, }, { enabled: !!sessionToken } );Session APIs are backend-only. When the client is configured with a publishable key, session-related methods (e.g. starting, verifying, refreshing sessions) are not available from the client and will throw. Sessions must be managed only on your backend; the frontend only passes the token in the
sessionfield of each request.
Documentation
See the main Ductape documentation for the full security model (publishable key, session required in params, and backend-only session management).
