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
- Obtain the caller from trusted authentication.
- Load the requested resource and relevant membership information.
- Evaluate the action against the resource’s organization and ownership.
- Deny by default and record sensitive administrative actions without leaking credentials.
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.
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.
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.
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
Answer the understanding check correctly to record exercise completion.
Related interview practice
These scenarios add constraints and follow-up questions to the concepts you just learned.
Further reading
- OWASP: authentication ↗
- OWASP: password storage ↗
- OWASP: session management ↗
- MDN: Set-Cookie ↗
- IETF: JWT best current practices ↗
Selected primary references · reviewed 2026-10-09. Examples are educational; use your framework’s documented integration guidance when building a deployed system.