DEV Community

mark vachi
mark vachi

Posted on

How to Register Permissions in Strapi Plugin

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);
};
Enter fullscreen mode Exit fullscreen mode

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,
        },
      ],
    });
  },
};
Enter fullscreen mode Exit fullscreen mode

Summary

These steps allow you to register and manage permissions effectively within your Strapi plugin.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay