AuthorizeMiddleware class
Authorization Middleware.
Checks if the authenticated user has the specified ability before
allowing navigation. This is Laravel's can middleware equivalent.
Usage
Register in Kernel with ability name:
Kernel.register('can:edit-post', () => AuthorizeMiddleware('edit-post'));
Kernel.register('can:delete-post', () => AuthorizeMiddleware('delete-post'));
Use in routes:
MagicRoute.page('/posts/:id/edit', () => EditPost())
.middleware(['auth', 'can:edit-post']);
Gating resolves in the router's redirect callback (pre-build) via
redirectTarget, so a denied route never builds and the unauthorized
destination mounts exactly once.
- Inheritance
-
- Object
- MagicMiddleware
- AuthorizeMiddleware
Constructors
- AuthorizeMiddleware(String ability, {dynamic arguments, String unauthorizedRoute = '/unauthorized'})
- Create an authorization middleware.
Properties
- ability → String
-
The ability to check.
final
- arguments → dynamic
-
Optional arguments to pass to the ability check.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
The route to redirect to when unauthorized.
final
Methods
-
handle(
void next()) → Future< void> -
Handle the navigation request.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
redirectTarget(
String location) → String? -
Resolve a redirect target for
locationBEFORE the route builds.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited