@thorgate/spa-permissions
v1.0.0-beta.4
Published
Permissions helpers used by Thorgate project template SPA variant
Downloads
18
Readme
@thorgate/spa-permissions
Permissions helpers used by Thorgate project template SPA variant
Used by view to provide user and authentication information stored in Redux state to the components inside the view. Consider using view and view-manager with this package.
Usage
LoginRequired
If used as decorator on a component, displays "Insufficient permissions" error message to unauthenticated users instead.
import { loginRequired } from '@thorgate/spa-permissions';
import React from 'react';
const Restricted = () => (
<div>If you can see this, you are authenticated</div>
);
export default loginRequired(Restricted);
Checking for other permissions
In a similar way as LoginRequired
, more complex functions with signature permissionCheckFn: (props) => boolean
may be used to define view access permissions. Wrap's base view with permissionCheck
decorator
to handle permission check.
import { permissionCheck } from '@thorgate/spa-permissions';
import React from 'react';
const checkIfNotAuthenticated = ({ isAuthenticated }) => !isAuthenticated;
const RestrictedToGuests = () => (
<div>If you can see this, you are not authenticated</div>
);
export default permissionCheck(checkIfNotAuthenticated)(RestrictedToGuests);
It is also possible to use PermissionCheck
component directly.