This topic describes how to configure the manifest
file to set permissions for a micro application. For more information, see Description Protocol.
Assume that permissions have been configured in manifest.json
.
{"privileges": [{"name": "lang.register","code": "PRODUCT_REGISTER"}]}
hasPermission
methodWe can use the function microProps.hasPermission
exported from the entry file (assume that the entry file is src/index.tsx
) to check for the permissions of a user. The request parameter is the value of the permission code
configured in manifest.json
. The return value of Boolean type indicates whether the user has the required permission.
interface HasPermission {(code: string): boolean;}
Usage in a component:
import { microProps } from 'src/index';export default () => {return microProps.hasPermission('PRODUCT_REGISTER') ? (<div>Permitted</div>) : (<div>Not Permitted</div>);};
In your local development environment, edit the micro.config.js
> debuggerConfig
> mockPermissions
variable.
The data type of mockPermission
is as follows:
type Code = string;type MockPermissions = Code[];
Code
is the code of each element in the privileges
array configured in the manifest.json
file.
To grant a local micro application the permission PRODUCT_REGISTER
, you can edit micro.config.js
:
module.exports = {debuggerConfig: {...,mockPermissions:['PRODUCT_REGISTER']},};