OxL Reference

method Principal.has

caller.has(role: .Support) (§13.2, D-5011): the caller is a user who has that role. R is the application's role enum (roles from claim("roles") as AppRole): the compiler types the argument as that enum, the runtime compares variant names.

Example:

oxl
// needs `cluster app { auth { ...; roles from claim("roles") as AppRole } }` for the role type
enum AppRole { Support, Admin }

fn canRefund(caller: Principal) -> bool {
  caller.has(role: .Support)
}
pub(api) fn has<R: Show>(role: R) -> bool

Complexity. O(roles).

Since. 1.0.0-beta

Parameters

NameType
roleR

Returns

bool

Effects

none declared (pure unless the body says otherwise)

Defined in: std/core/rpc.oxl:103

See also