Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Invites

use auth_chad::core::policy::Policy;
use auth_chad::{Authenticated, Config, Store, Tenant};
use auth_chad::axum::Hooks;

fn invite_only(config: Config) -> Config {
    config.with_policy(Policy::invite_only())
}

#[derive(Clone)]
struct App;

impl<S: Store> Hooks<S> for App {
    async fn may_invite(&self, _: &S, who: &Authenticated, tenant: Tenant) -> bool {
        tenant == Tenant::ROOT && who.is_first_party()   // replace with: is this user an admin?
    }
}

POST /auth/invites gives a token once. For a tenant: /auth/tenants/{name}/invites, and the new user becomes a member. The link is https://app.example.com/signup?invite=<token>, for one account and 7 days. GET lists and DELETE /auth/invites/{id} cancels.

The first account, from the host: signup::create_invite(&ctx, &mut draws, None, None, "admin"), then commit. The last argument is your own data: it comes back in Created.invite at signup.

data in POST /auth/invites is your own data too, and the list shows it. If it gives rights, check it in Hooks::invite_data: the default stores what the person asked for, so an admin could make admin invites.