Skip to content

3.0.2

Choose a tag to compare

@necessarylion necessarylion released this 01 Nov 04:18
· 21 commits to main since this release
cfa2964

New: gates and policies

Say what a user may do, like "a user may edit only their own post".

Gate.define('update-post', (User user, Post post) => post.userId == user.id);
Gate.policy<Post>(PostPolicy());

await req.authorize('update', post);   // guest: 401, not allowed: 403
Route.put('/posts/{post}', [AuthMiddleware(), Can('update', param: 'post'), update]);
  • Gate.allows, denies, authorize, any, all, and before / after hooks.
  • GateResponse.deny('reason') sets the message of the 403.

Docs: Security → Authorization.