Course contentsShow
← Web Development
Lesson 1640 of 2,98230. Web Authorization PatternsFree lesson

Permission Data Structures

Designing permission objects and arrays to represent user capabilities and access levels efficiently.

Permission Data Structures

You'll learn how to organize permission data in your frontend code so you can quickly and reliably check what actions a user is allowed to perform.

The Challenge

Once you've validated who a user is (authentication) and need to control what they can do (authorization), you need a clean way to represent their capabilities. Raw string comparisons scattered throughout your code lead to bugs, inconsistency, and maintenance nightmares.

Structuring Permissions

Think of permissions like a key ring: some keys open specific doors, others unlock entire floors. You need a data structure that's both human-readable and efficient to check.

Simple Array Approach:

const userPermissions = [
  'posts:read',
  'posts:create',
  'comments:read',
  'comments:delete'
];

Object-Based Approach:

const userPermissions = {
  posts: ['read', 'create', 'edit'],
  comments: ['read', 'delete'],
  settings: ['view']
};

Boolean Flag Object:

const userPermissions = {
  canCreatePosts: true,
  canDeleteComments: true,
  canEditSettings: false
};

The array approach works well for checking single permissions (permissions.includes('posts:create')). The object structure shines when you need to check multiple operations on a resource (permissions.posts.includes('edit')). Boolean flags offer the fastest lookups but can become unwieldy with many permissions.

When It Arrives

Your backend typically sends this structure after login or fetches it with user profile data. Store it in your state management solution (context, Redux, etc.) so all components can access it consistently.

Key Takeaway: Choose a permission data structure based on how you'll query it—arrays for simple checks, nested objects for resource-based permissions, and boolean flags for high-frequency lookups. Consistency matters more than the specific format.