Skip to main content

MagicLinkRepository

Trait MagicLinkRepository 

Source
pub trait MagicLinkRepository: Send + Sync {
    // Required methods
    fn save<'life0, 'life1, 'async_trait>(
        &'life0 self,
        link: &'life1 MagicLink,
    ) -> Pin<Box<dyn Future<Output = Result<(), AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn find_by_token_hash<'life0, 'life1, 'async_trait>(
        &'life0 self,
        token_hash: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<MagicLink>, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn mark_consumed<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = Result<(), AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}

Required Methods§

Source

fn save<'life0, 'life1, 'async_trait>( &'life0 self, link: &'life1 MagicLink, ) -> Pin<Box<dyn Future<Output = Result<(), AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Persist a freshly issued MagicLink. Caller guarantees token_hash uniqueness (sha256 of 256-bit random token is collision-free in practice).

Source

fn find_by_token_hash<'life0, 'life1, 'async_trait>( &'life0 self, token_hash: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<MagicLink>, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Look up a link by its token_hash (already hashed by the caller). Returns Ok(None) if no record matches — callers must translate this to AppError::MagicLinkInvalid so a forged token and an unknown token are indistinguishable from the client side (no enumeration).

Source

fn mark_consumed<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Atomically mark a link as consumed (sets consumed_at = NOW()). The implementation MUST be a single UPDATE ... WHERE id = $1 AND consumed_at IS NULL so two concurrent consumers cannot both succeed (race-free single-use guarantee).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§