Roles (Access Management) Recipe

Control/management of access through setting and assigning user roles and permissions are an important part of most production applications.

Though there are many patterns, we are going to use the following terminology:

Role - job function or title which defines authority level (i.e. admin or manager). A user has a role, a role as permissions.

Permissions - approval of a mode of access (i.e. todos) . Multiple permissions can be assigned to a single role.

Data Setup

Add the Roles collection in Firebase. It should be a sibling of the users collection. For example:

Tip: you can import below JSON directly into Firebase. Alternatively, you can upload it in the start of your application or when you deploy to Firebase.

{
admin:{
name:'admin',// will not be necessary once profileParamsToPopulate supports keyProp
todos:true,
userManagement:true},
user:{
todos:true,
name:'user'// will not be necessary once profileParamsToPopulate supports keyProp}}{
users:{...}}

The role parameter on users

Each user should have a role parameter that correlates to a role. For example:

Config

In order for us to check our role for permissions, we will want to populate the role on a profile. This will turn the role string (i.e. admin) into the object representing that role from the roles collection.