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

A way back into an account

Offer a second passkey first. Then choose:

MethodRoutes below /authThe application doesStrength
Recovery keyrecovery/key, recovery/key/start, recovery/key/finishNothing, if users have an identifierStrong
Approval by an ownerrecovery/owner, then the linkHooks::may_recoverStrong, if people check each other
Emailrecovery/email, then the linkConfig::with_email_recovery, verified_address, sendWeak: 24 hours of waiting, notices, 72 hours of hold
use auth_chad::axum::{Hooks, Mail};
use auth_chad::sqlite::SqliteStore;
use auth_chad::{Authenticated, UserId};

struct App;

impl Hooks<SqliteStore> for App {
    async fn verified_address(&self, _store: &SqliteStore, address: &str) -> Option<UserId> {
        None   // look up an address that you verified, never one that a person only typed
    }

    async fn may_recover(&self, who: &Authenticated, user: UserId) -> bool {
        false  // is `who` an owner of an organization of `user`?
    }

    async fn send(&self, mail: Mail<'_>) -> bool {
        match mail {
            // A secret. The link opens a page with a button: mail scanners open links.
            Mail::Link { to, token } => false,
            // "Someone asked for a new passkey. It works at … . Cancel it here."
            Mail::Notice { to, ready_at } => false,
        }
    }
}

In the browser (/auth/auth-chad.js):

const text = await newRecoveryKey();                                  // show it once; needs a recent passkey
await recoverWithKey({ identifier: "jane", displayName: "Jane", key: text });
await recoverByEmail("jane@example.com");                             // the same answer if there is no account
await recoverWithLink({ token, userName: "jane", displayName: "Jane" });
const { ready_at, hold_until } = await recovery();                    // show it: cancelRecovery(), undoRecovery()
  • Run the worker (auth_chad::axum::work, see load-balancer): it sends a mail that failed again.
  • Show ready_at on every page of a logged-in user. A cancel there stops someone who has the mailbox.
  • Use Hooks::commit_recovery to add a notice for every other address of the user.

Never use email recovery with e2ee: it cannot restore a key.