Skip to main content

Protect

Shows its children only when the signed-in person passes an authorization check. The check can be a permission, a relationship or an attribute policy.

ComponentReadyView source
Works with
ReactNext.js

In this preview the sample person holds documents.edit and is a viewer of the Q3 report, and does not hold billing.manage.

Installation​

npm install @lumoauth/react

Usage​

import { Protect } from '@lumoauth/react';

<Protect permission="documents.edit" fallback={<ReadOnlyBanner />}>
<Editor />
</Protect>

Protect asks LumoAuth with the access token of the signed-in person, and shows a spinner until the answer arrives. It shows fallback when the answer is no and when nobody is signed in.

This hides UI. It does not protect data.

A person can change what a browser shows. Check the same permission again in your API before you return or change anything. The route protection recipe shows that check in each server SDK.

Three kinds of check​

Give exactly one of the three props.

PropModelQuestion
permissionRoles and permissionsDoes a role of this person hold the permission documents.edit?
zanzibarRelationshipsIs this person a viewer of document:q3-report?
abacAttribute policiesDo the policies allow this person to read a document, given the attributes of both?

The abac check needs the scope abac:read. Add it to the scope prop of the provider.

Props​

PropTypeDescription
permissionstringThe permission to check, for example documents.edit.
zanzibar{ object: string; relation: string; subject?: string }A relationship check. Without subject, the subject is the signed-in person.
abac{ resourceType: string; action: string; resourceId?: string }An attribute policy check.
fallbackReactNodeWhat to show when access is denied.
childrenrequiredReactNodeWhat to show when access is granted.