koprogo_api/application/ports/
two_factor_repository.rs

1use crate::domain::entities::TwoFactorSecret;
2use async_trait::async_trait;
3use uuid::Uuid;
4
5/// Repository port for two-factor authentication secrets
6#[async_trait]
7pub trait TwoFactorRepository: Send + Sync {
8    /// Create a new 2FA secret for a user
9    async fn create(&self, secret: &TwoFactorSecret) -> Result<TwoFactorSecret, String>;
10
11    /// Find 2FA secret by user ID
12    async fn find_by_user_id(&self, user_id: Uuid) -> Result<Option<TwoFactorSecret>, String>;
13
14    /// Update 2FA secret (enable, disable, mark used, etc.)
15    async fn update(&self, secret: &TwoFactorSecret) -> Result<TwoFactorSecret, String>;
16
17    /// Delete 2FA secret (when user disables 2FA)
18    async fn delete(&self, user_id: Uuid) -> Result<(), String>;
19
20    /// Find all users with enabled 2FA that need reverification (not used in 90 days)
21    async fn find_needing_reverification(&self) -> Result<Vec<TwoFactorSecret>, String>;
22
23    /// Find all users with low backup codes (< 3 remaining)
24    async fn find_with_low_backup_codes(&self) -> Result<Vec<TwoFactorSecret>, String>;
25}