Authorization
Last updated
Was this helpful?
Last updated
Was this helpful?
Novel uses the CASL library to provide authorization checks for all the routes and actions you need for your SaaS.
In /config/auth.js
there is a roles object that you can modify to add role IDs and permission keys to.
You can add as many roles you need here, and as many permissions applied to the role here.
These are then auto-loaded during start up time and applied to a global authorizer and a session based authorizer.
The Permission
object is a class that you can use to organize permissions in your application.
new Permission(ObjectWithId)
This creates a new Permission object that can be serialized later on. You can use this to temporarily create permissions in your feature code.
You can persist the permissions to database using .persist()
below.
permit.allow(action: String, subject: String | ObjectWithId)
This defines what you can use in the Permission object using the CASL Ability .can
or .cannot
. The signature for this is the same.
permit.deny(action: String, subject: String | ObjectWithId)
This is the opposite of allow you can use in the Permission object using the CASL Ability .can
or .cannot
. The signature for this is the same.
permit.build(): Ability
This is an internal abstraction to CASL's Ability.build function. This makes it so that you can perform CASL functions against the Permission Object
await permit.persist()
This persists the permissions defined during the lifecycle of the Permission object. It generates a serialized permission records, one row per action/scope into the access_control
table.
await Permission.fetch(actor: String | ObjectWithId)
This is similar to new Permission(ObjectWithId)
but for an actor that has been persisted.
It is important to be familiar with both authorization modes of Novel API. Discussed below:
Combine the above with the request helpers associated with permit.allow
and permit.deny
.
2024-12-20 - Initial Documentation