Loading Depth Study
Preparing your workspace
Some authorization decisions depend not only on a user's role but also on the specific resource being accessed.
A rule such as 'users can edit their own profile' cannot be enforced by role alone. The server must compare the authenticated user's identity with the resource owner. Multi-tenant systems may also need to verify that the user belongs to the same organization as the resource. This is sometimes called object-level or resource-level authorization. These checks should happen at trusted backend or database boundaries.
A student may edit their own profile but not another student's profile, while a mentor may access only students assigned to them.
if (resource.userId !== currentUser.id) {
return forbidden();
}
if (resource.organizationId !== currentUser.organizationId) {
return forbidden();
}
return allowAccess();The request is allowed only when the authenticated user owns the resource and belongs to the correct organization.