OxL Reference

method Ctx.userId

The id of the calling user; AccessDenied when the caller is not a user (ctx.caller.userId(), §13.2).

Example:

oxl✓ checked in CI
service Whoami {
  @public rpc me() -> str
}

impl Whoami {
  rpc me() {
    match ctx.userId() {
      str id => id
      AccessDenied _ => "anonymous"
    }
  }
}

fn main() io, net {
  print("{Whoami.me()!}")
}
Output
anonymous
pub(api) fn userId() -> str | AccessDenied

Since. 1.0.0-beta

Returns

str

Errors

  • AccessDenied @error
  • `AccessDenied` when the caller is not a user.

Effects

none declared (pure unless the body says otherwise)

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

See also