Support: see the application as a user
Nobody may, until the application says so.
use auth_chad::axum::{Caller, Hooks, InPerson, ViewMode};
use auth_chad::sqlite::SqliteStore;
use auth_chad::{Authenticated, UserId};
struct App;
impl Hooks<SqliteStore> for App {
async fn may_view(&self, who: &Authenticated, user: UserId) -> Option<ViewMode> {
None // is `who` support staff, and may they see this user? Some(ViewMode::ReadOnly)
}
}
// Only the user in person: a billing portal, a data export, an address change.
async fn export(who: InPerson) -> String {
format!("{:?}", who.user())
}
// For an audit: both people.
fn people(caller: &Caller) -> Option<(UserId, Option<UserId>)> {
let who = caller.who().ok()?;
Some((who.user().ok()?, who.view().map(|v| v.by)))
}
In the browser: await viewAs(user) from a click, with a recent passkey. session() then has view: show it on every page,
with a button for await endView().
What the library does, without a list of paths to maintain:
FreshLoginrefuses a view. So every sensitive action of the application refuses it.- The account API refuses it: passkeys, sessions, devices, apps, recovery, invites, signed links, events.
ReadOnlyallows only safe methods. AGETthat changes something is a mistake of the application.- A view ends after an hour, with the person’s own login, if either account is disabled, and if the user ends it in the list of sessions. It needs the person’s own cookie beside it.
- After the end, requests fail with
view_endeduntilendView(). They never continue as the person’s own account. - Both people have an event with the other’s ID:
viewedandview_as.
A handler with FirstParty accepts a view. Use InPerson where only the user may act.