Skip to main content

MagicCodeBackend

Trait MagicCodeBackend 

Source
pub trait MagicCodeBackend: Send + Sync {
    // Required methods
    fn put(&self, email: &str, code: &MagicCode);
    fn get(&self, email: &str) -> Option<MagicCode>;
    fn remove(&self, email: &str);
    fn bump_attempts(&self, email: &str);
    fn load_all(&self) -> Vec<MagicCode>;
}
Expand description

Pluggable storage for magic-code records. In-memory is the default (fine for dev); persistent backends (SQLite, Postgres) live in pylon-runtime so a server restart between “send code” and “verify code” doesn’t invalidate the user’s pending login.

All methods are infallible from the caller’s perspective — durability is best-effort. A backend that fails to write should log; the in-memory cache remains authoritative for the current process.

Required Methods§

Source

fn put(&self, email: &str, code: &MagicCode)

Replace any existing code for email with code.

Source

fn get(&self, email: &str) -> Option<MagicCode>

Look up the current code for email. Returns None if absent.

Source

fn remove(&self, email: &str)

Remove the code for email (called on successful verify or expiry). Idempotent — missing key is not an error.

Source

fn bump_attempts(&self, email: &str)

Persist an attempts++ on the existing record without touching other fields. Used by the verify-failed path to enforce MAX_ATTEMPTS across restarts.

Source

fn load_all(&self) -> Vec<MagicCode>

Load all live records on construction. Lets MagicCodeStore::with_backend hydrate the in-memory cache from durable storage on startup.

Implementors§