LEARN. PRACTICE. EXPLAIN.
Learning paths & interview practiceP
Backend foundations
LESSON 7 OF 8 · ABOUT 14 MINUTES + EXERCISE

How do roles, permissions, and ownership work?

THE IDEA

What it is

A role groups capabilities, a permission allows an action, and ownership or tenant membership restricts the resources that action applies to. Authorization combines these facts. An editor role in one organization does not automatically permit edits in another organization.

Why you need it

Access rules rarely fit a single isAdmin boolean. A small explicit policy makes the important conditions visible and creates a useful table for testing.

How it works

  1. Obtain the caller from trusted authentication.
  2. Load the requested resource and relevant membership information.
  3. Evaluate the action against the resource’s organization and ownership.
  4. Deny by default and record sensitive administrative actions without leaking credentials.
JavaScript

A small ownership rule

function canReadInvoice(user, invoice) {
  return user.organizationId === invoice.organizationId
    && (user.id === invoice.ownerId
      || user.permissions.includes("invoice:read:any"));
}

This pure function assumes both objects came from trusted server records. Cross-organization support access, if needed, requires a separate explicit and audited policy rather than bypassing this condition accidentally.

Try the local authentication lab

Download the file and run node backend-auth.mjs with Node.js 22 or newer. It tests an in-memory auth model; it is not a production login server.

Download runnable lab

Good practices and why

  • Centralize reusable rules while passing the actual action and resource context.
  • Re-evaluate changed permissions at the required freshness boundary instead of trusting indefinitely stale token claims.

Common mistakes

  • Using unguessable resource IDs as the only protection.
  • Assuming permission to list a resource also implies permission to modify or export it.
GUIDED IMPLEMENTATION

Try it yourself

Create a table with owner, same-organization non-owner, cross-organization caller, and permitted administrator. Evaluate read and update separately.

What a successful result looks like

The table includes denials and tenant boundaries, and each expected result follows an explicit policy.

0 / 6000 characters · Saved on this device. Do not include passwords or private data.

Check your understanding

A user is an editor in organization A. What permits an update to a record in B?

Answer the understanding check correctly to record exercise completion.

PUT THE IDEA UNDER PRESSURE

Related interview practice

These scenarios add constraints and follow-up questions to the concepts you just learned.

Further reading

Selected primary references · reviewed 2026-10-09. Examples are educational; use your framework’s documented integration guidance when building a deployed system.

AlifBay Prep