Skip to content

Interface: ScopedNextRbac<T, G> ​

Defined in: packages/next/src/server.ts:154

The helpers of createNextRbac() when the engine has per-guard names (RbacTypeConfig['guards']): like NextRbac, but G is the guard of the checks (the guard option of createNextRbac(), else the default guard), and a call's { guard } takes the names of that guard instead: can('orders.read', { guard: 'api' }).

Type Parameters ​

Type ParameterDefault type
T extends RbacTypeConfig-
G extends stringDefaultGuardName<T>

Properties ​

PropertyTypeDefined in
rbacRbac<T>packages/next/src/server.ts:155

Methods ​

authorize() ​

ts
authorize<Q, G2>(requirement, scope?): Promise<AuthorizeResult>;

Defined in: packages/next/src/server.ts:158

Non-throwing check: who is the user and do they meet the requirement?

Type Parameters ​

Type ParameterDefault type
Q extends Requirement-
G2 extends stringG

Parameters ​

ParameterType
requirementQ & CheckRequirement<Q, T, G2>
scope?ScopeOptions<CheckGuard<T, G2>>

Returns ​

Promise<AuthorizeResult>


can() ​

ts
can<G2>(permission, scope?): Promise<boolean>;

Defined in: packages/next/src/server.ts:164

Type Parameters ​

Type ParameterDefault type
G2 extends stringG

Parameters ​

ParameterType
permissionPermissionName<T, G2>
scope?ScopeOptions<CheckGuard<T, G2>>

Returns ​

Promise<boolean>


canAll() ​

ts
canAll<G2>(permissions, scope?): Promise<boolean>;

Defined in: packages/next/src/server.ts:166

Type Parameters ​

Type ParameterDefault type
G2 extends stringG

Parameters ​

ParameterType
permissionsMany<PermissionName<T, G2>>
scope?ScopeOptions<CheckGuard<T, G2>>

Returns ​

Promise<boolean>


canAny() ​

ts
canAny<G2>(permissions, scope?): Promise<boolean>;

Defined in: packages/next/src/server.ts:165

Type Parameters ​

Type ParameterDefault type
G2 extends stringG

Parameters ​

ParameterType
permissionsMany<PermissionName<T, G2>>
scope?ScopeOptions<CheckGuard<T, G2>>

Returns ​

Promise<boolean>


getSnapshot() ​

ts
getSnapshot(scope?): Promise<RbacSnapshot>;

Defined in: packages/next/src/server.ts:163

Roles & permissions of the current user — pass to <RbacProvider snapshot={...}>. Guests get an empty snapshot.

Parameters ​

ParameterType
scope?ScopeOptions<string>

Returns ​

Promise<RbacSnapshot>


getSubject() ​

ts
getSubject(): Promise<Subject | null>;

Defined in: packages/next/src/server.ts:156

Returns ​

Promise<Subject | null>


hasAllRoles() ​

ts
hasAllRoles<G2>(roles, scope?): Promise<boolean>;

Defined in: packages/next/src/server.ts:169

Type Parameters ​

Type ParameterDefault type
G2 extends stringG

Parameters ​

ParameterType
rolesMany<RoleName<T, G2>>
scope?ScopeOptions<CheckGuard<T, G2>>

Returns ​

Promise<boolean>


hasRole() ​

ts
hasRole<G2>(role, scope?): Promise<boolean>;

Defined in: packages/next/src/server.ts:168

true if the user has the role — or ANY of the roles when given an array.

Type Parameters ​

Type ParameterDefault type
G2 extends stringG

Parameters ​

ParameterType
roleMany<RoleName<T, G2>>
scope?ScopeOptions<CheckGuard<T, G2>>

Returns ​

Promise<boolean>


requirePermission() ​

ts
requirePermission<S, G2>(permission, opts?): Promise<Subject>;

Defined in: packages/next/src/server.ts:174

Ensures the user has the permission (or ANY of the permissions). Returns the subject. Guests: redirect(loginUrl) or notFound(). Missing permission: notFound(). Both configurable.

Type Parameters ​

Type ParameterDefault type
S extends Many<string>-
G2 extends stringG

Parameters ​

ParameterType
permissionS & CheckNames<S, PermissionName<T, G2>>
opts?RequireOptions<CheckGuard<T, G2>>

Returns ​

Promise<Subject>


requireRole() ​

ts
requireRole<S, G2>(role, opts?): Promise<Subject>;

Defined in: packages/next/src/server.ts:179

Ensures the user has the role (or ANY of the roles). Returns the subject.

Type Parameters ​

Type ParameterDefault type
S extends Many<string>-
G2 extends stringG

Parameters ​

ParameterType
roleS & CheckNames<S, RoleName<T, G2>>
opts?RequireOptions<CheckGuard<T, G2>>

Returns ​

Promise<Subject>


requireRoleOrPermission() ​

ts
requireRoleOrPermission<S, G2>(items, opts?): Promise<Subject>;

Defined in: packages/next/src/server.ts:184

Ensures the user has ANY of the given roles or permissions. Returns the subject.

Type Parameters ​

Type ParameterDefault type
S extends Many<string>-
G2 extends stringG

Parameters ​

ParameterType
itemsS & CheckNames<S, PermissionName<T, G2> | RoleName<T, G2>>
opts?RequireOptions<CheckGuard<T, G2>>

Returns ​

Promise<Subject>


withPermission() ​

ts
withPermission<S, Args, R, G2>(
   permission, 
   action, 
   scope?
): (...args) => Promise<R>;

Defined in: packages/next/src/server.ts:189

Wraps a server action; throws RbacUnauthorizedError unless the user has the permission (or ANY of them).

Type Parameters ​

Type ParameterDefault type
S extends Many<string>-
Args extends unknown[]-
R-
G2 extends stringG

Parameters ​

ParameterType
permissionS & CheckNames<S, PermissionName<T, G2>>
action(...args) => MaybePromise<R>
scope?ScopeOptions<CheckGuard<T, G2>>

Returns ​

(...args) => Promise<R>


withRbac() ​

ts
withRbac<Args, O>(handler, options): (...args) => Promise<Response>;

Defined in: packages/next/src/server.ts:204

Wraps a route handler. Responds 401 (guest) or 403 (missing role/permission) with a JSON body. Mirrors spatie's permission, role and role_or_permission middleware.

Type Parameters ​

Type Parameter
Args extends unknown[]
O extends WithRbacOptions

Parameters ​

ParameterType
handler(...args) => MaybePromise<Response>
optionsO & CheckRequirement<O, T, OptionsGuard<O, G>>

Returns ​

(...args) => Promise<Response>


withRole() ​

ts
withRole<S, Args, R, G2>(
   role, 
   action, 
   scope?
): (...args) => Promise<R>;

Defined in: packages/next/src/server.ts:195

Wraps a server action; throws RbacUnauthorizedError unless the user has the role (or ANY of them).

Type Parameters ​

Type ParameterDefault type
S extends Many<string>-
Args extends unknown[]-
R-
G2 extends stringG

Parameters ​

ParameterType
roleS & CheckNames<S, RoleName<T, G2>>
action(...args) => MaybePromise<R>
scope?ScopeOptions<CheckGuard<T, G2>>

Returns ​

(...args) => Promise<R>

Released under the MIT License. Inspired by spatie/laravel-permission.