-
Notifications
You must be signed in to change notification settings - Fork 1
Accessors
Accessors are checker for access to routes
First, make a accessor via singlighter
node singlighter make:accessor UserAgentAccessor
All accessors is in ~/Scripts/Accessors
, so UserAgentAccessor
is in ~/Scripts/Accessors/UserAgentAccessor.js
If accessor return true
, SinglightJs will routing user to the page, but if return false
, user get 403 Error
For example, i want create a accessor to check user agent, if contains Chrome
can access and if not, get 403 Error
export default function UserAgentAccessor() {
return navigator.userAgent.includes("Chrome");
}
Now i need to register accessor in the manager, import accessor in ~/Scripts/Accessors/Manager.js
import UserAgentAccessor from './UserAgentAccessor.js';
Then register it
export default {
UserAgentAccessor
};
For using accessors, write accessor name without Accessor
to fourth router parameter
router.addRoute("/", HomePage, null, "UserAgent");
And you can more than 1 accessors
router.addRoute("/", HomePage, null, "UserAgent,Ip,Auth");
// or
router.addRoute("/", HomePage, null, ["UserAgent", "Ip", "Auth"]);
NOTICE The old usage method also is available
router.addRoute("/", HomePage, null, () => false);
IMPORTANT SinglightJs is a front-end framework and accessors working on front-end, so DON'T use SinglightJs-Accessors for very important things