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:
// 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) -> boolComplexity. O(roles).
Since. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
role | R |
Returns
bool
Effects
none declared (pure unless the body says otherwise)
Defined in: std/core/rpc.oxl:103