A package for authorizing access to a collection of services in a React application.
To install the package, run the following command:
To use the package, follow these steps:
-
Import the
AuthorizationProvider
component from the package:import { AuthorizationProvider } from 'authorization-middleware';
-
Wrap your application with the AuthorizationProvider component, passing in the necessary props:
<AuthorizationProvider plugins={plugins}> <App /> </AuthorizationProvider>
The plugins prop should be a record of plugins, where each key is the name of the plugin and each value is the plugin function itself.
-
Use the useAuthorization hook in any child components that need to access the authorization middleware:
import { useAuthorization } from 'authorization-middleware'; function MyComponent() { const middleware = useAuthorization(); // Use the middleware function here // ... }
For more information on the usage of the package, see the API documentation.
The AuthorizationProvider
component is used to initialize the authorization middleware and provide it to child components. The component takes the following props:
plugins
(required): A record of plugins, where each key is the name of the plugin and each value is the plugin function itself.
pluginPaths
(optional): An array of paths that can be used to filter the plugins that are used for a specific request.
interface AuthorizationProviderProps {
plugins: Record<string, Plugin>;
pluginPaths?: string[];
}
<AuthorizationProvider plugins={plugins} pluginPaths={['/billing']}>
// Child components
</AuthorizationProvider>