Private Components
Overview
For the sake of user permission aspect, Private components in Still.js help manage user authorization for navigation and rendering. If a component is not public (isPublic = false
or unset), custom logic is required to control its visibility. Still.js allows blacklisting and whitelisting components based on custom requirements, overriding the isPublic
flag regardless of its value (true or false).
1. Making component private
This is a private component | |
---|---|
This is a private component | |
---|---|
In the example above, the NewAccountForm component includes buttons to navigate to private components, causing an Unauthorized acces
warning and not rendering the component. To allow navigation, two approaches can be used separately or in combination and they can be set through the StillAppSetup
(app-setup.js file):
-
setAuthN - For the Application context, when the AuthN is set to true (
this.setAuthN(true)
), it understands that navigation to/ embeding such component can happen at all levels, anyway, there might be some exception which cannot be addressed here. -
setWhiteList - It's possible to specify a list of components that should be whitelisted, by doing that, even if the component is private, it'll always be accessible.
1.1 Allowing private component access through authN
flag
The authN
flag is configured at the application level in the StillAppSetup
class (app-setup.js
). It is set using .setAuthN(true)
in the custom authentication logic to indicate that the user is authenticated, allowing access to all components, including private ones. Having the same sample project from point 1 only edit the app-setup.js
as follow:
1.2 Using whiteList
to allow access to Private component
In addition to setAuthN
flag approach, setWhiteList
is another way to make a private component accessible, in this case we have to pass an array of all components that we want to make accessible although it's private. Having the same sample project from point 1 only edit the app-setup.js
as follow:
Whitelist behind the scenes
whiteList components
can only be set once, means, if setWhiteList()
is call more than once, only the first call will take affect, therefore changing it the runtime does not work, nevertheless, multiples list can yet be set and combined with the appropriate application logic/flow, so alternative flows can take place.
2 Using blackList
to make a component private (not accessible)
The blacklist is used to restrict access to specific components or parts of the application, even for authenticated users. When combined with business logic, it ensures that components listed in the blacklist remain inaccessible—regardless of a successful .setAuthN(true)
call—preventing access via both navigation and embedding. Having the same sample project from point 1 only edit the app-setup.js
as follow:
Blacklist precedence and considerations
-
Blacklist has hte highest precedence in case it's combined with
authN
flag orwhiteList
, no matter in what order they are called, onceblackList
takes this hieghst priority if when a component is found there. -
blackList components
can only be set once, means, just as thewhiteList
(see explanation).
Component rendering will be affectid by the component visibility (public, private), nevertheless, therefore, this happens in the application level, however Still.js also provides with (renderIf) directive which allows controling component in the component level by putting such directive in the template for a specific HTML tag as shown in this example.