Registering permissions in a Strapi plugin helps manage user access to specific actions. Here’s a quick guide:
Step 1: Define Permission Actions
In bootstrap.ts, define the permission action:
// src/plugins/exporter/server/bootstrap.ts
import { Strapi } from '@strapi/strapi';
export default ({ strapi }: { strapi: Strapi }) => {
registerPermissionActions();
};
const registerPermissionActions = async () => {
const actions = [
{
section: 'plugins',
displayName: 'Export',
uid: 'export',
pluginName: 'exporter',
},
];
await strapi.admin.services.permission.actionProvider.registerMany(actions);
};
Step 2: Add Permissions to the Admin Menu
In index.tsx, link the permission to the admin interface:
// src/plugins/exporter/admin/src/index.tsx
export default {
register(app: any) {
app.addMenuLink({
// other properties
permissions: [
{
action: 'plugin::exporter.export', // Format: plugin::plugin-name.actionType
subject: null,
},
],
});
},
};
Summary
These steps allow you to register and manage permissions effectively within your Strapi plugin.
Top comments (0)