Secure Route Component

Using SecureRoute React component

The SecureRoute component prevents rendering of a route if a user doesn't possess required security scopes.

To learn more about scopes, click here.

The following example shows how to use the SecureRoute component in order to prevent users from accessing a route if they don't possess the library:books:get security scope:

import { SecureRoute } from "@webiny/app-security/components";
function SecureBookRoute() {
return (
<SecureRoute
scopes={["library:books:get"]}
>
<Book />
</SecureRoute>
)
}

If a user doesn't posses required security scopes, by default, the component will just render a simple "You are not authorized to view this route." message. If needed, this fallback render can be customized via a secure-route-error plugin.

Last updated on by Pavel Denisjuk