Keeping permissions in sync
The permissions associated with each role are persisted in the database. This means we will need to make sure that the permissions we created while developing the application are kept in sync when we move to a new environment or when we seed the database with a new role. For example, in the previous section, we dropped and recreated the Admin role; by doing so, we lost all the previous permissions we configured for this role.
To keep the permissions in sync, we will again make use of the bootstrap
function. We can add a new function that will enable permissions for a specific role when the server starts up. Let's get coding, as follows:
- In the
src/index.js
file, let's create a newenablePermission
function that accepts three parameters, as follows: theroleType
parameter for the role for which we want to enable the permission, thecontroller
parameter, and theaction
parameter for the action we want to enable. The code is illustrated...