morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::session::Principal Struct Reference

The signed-in user's verified identity, readable outside a dispatch. More...

#include <session.hpp>

Public Member Functions

bool hasRole (std::string_view role) const
 Returns true if roles contains role.

Public Attributes

std::string id
 Verified identity (e.g. username), as returned by the server. Empty if signed out.
std::vector< std::string > roles
 Coarse-grained roles the app can gate UI on (e.g. "editor", "admin").
std::unordered_map< std::string, std::string > claims
 Free-form bag of string→string claims beyond id/roles.

Detailed Description

The signed-in user's verified identity, readable outside a dispatch.

Context::principal only exists during a dispatch — session::current() returns nullptr outside one, so UI code (a button's enabled state, a menu item's visibility) has no way to ask "who is signed in and what may they do?" without attempting the action and catching the failure. Principal is the longer-lived counterpart an application installs once, typically right after a successful login dispatch, and reads from UI code to shape itself instead: bridge.currentPrincipal().hasRole("editor").

Deliberately not a process-wide global: the caller installs it on the specific Bridge (or other session-scoped object) whose backend it came from — see Bridge::setPrincipal/Bridge::currentPrincipal (core/bridge.hpp) — rather than one ambient value shared by every backend a process happens to hold.

Warning
Populate this only from data the server actually returned (e.g. an action's Result, such as the bank example's AuthResult), never from a client-side guess — the server remains the sole authority for what a principal may do; this is a read-only cache of what it last told the client, not a second, independently-decided permission set. Roles can change server-side mid-session, so every dispatch is still authorized there regardless of what a stale Principal says client-side; this only shapes the UI, it never replaces server-side authorization.

Definition at line 78 of file session.hpp.

Member Function Documentation

◆ hasRole()

bool morph::session::Principal::hasRole ( std::string_view role) const
inlinenodiscard

Returns true if roles contains role.

Parameters
roleRole name to look for.
Returns
true if role is present in roles.

Definition at line 91 of file session.hpp.

Member Data Documentation

◆ id

std::string morph::session::Principal::id

Verified identity (e.g. username), as returned by the server. Empty if signed out.

Definition at line 80 of file session.hpp.

◆ roles

std::vector<std::string> morph::session::Principal::roles

Coarse-grained roles the app can gate UI on (e.g. "editor", "admin").

Definition at line 83 of file session.hpp.

◆ claims

std::unordered_map<std::string, std::string> morph::session::Principal::claims

Free-form bag of string→string claims beyond id/roles.

Definition at line 86 of file session.hpp.


The documentation for this struct was generated from the following file: