GateManager class

The Gate Manager.

Manages authorization abilities and their checks. This class stores ability definitions and executes permission checks against the authenticated user.

Philosophy

Authorization is client-side for simplicity. We check Auth.user() properties against defined rules. For sensitive operations, always validate on the server as well.

Events

The Gate system fires the following events:

  • GateAbilityDefined - When a new ability is registered
  • GateAccessChecked - After every ability check (allowed or denied)
  • GateAccessDenied - When an ability check results in denial

Usage

// Define abilities
gate.define('edit-post', (user, post) => user.id == post.userId);

// Check abilities
if (gate.allows('edit-post', post)) {
  // User can edit
}

Constructors

GateManager()

Properties

abilities List<String>
Get all defined abilities.
no setter
hashCode int
The hash code for this object.
no setterinherited
mostRecentResult GateResult?
Return the most recently recorded GateResult across all abilities, or null when no check has run yet.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

allows(String ability, [dynamic arguments]) bool
Check if the authenticated user has the given ability.
allowsAll(List<String> abilities, [dynamic arguments]) bool
Check if the authenticated user has every one of the given abilities.
allowsAny(List<String> abilities, [dynamic arguments]) bool
Check if the authenticated user has any of the given abilities.
before(BeforeCallback callback) → void
Register a "before" callback.
check(String ability, [dynamic arguments]) bool
Alias for allows.
define(String ability, AbilityCallback callback) → void
Define an ability with a callback.
denies(String ability, [dynamic arguments]) bool
Check if the authenticated user is denied the given ability.
flush() → void
Clear all defined abilities, before callbacks, and the lastResult cache.
has(String ability) bool
Check if an ability has been defined.
lastResult(String ability) GateResult?
Return the most recent GateResult for ability, or null when the ability has never been checked (or its entry was evicted).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited