code refactor
Some checks failed
CI / Check / Test (push) Has been cancelled

Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
2026-10-26 09:36:23 +00:00
parent 2ce7db12c2
commit 017b58d6fa
804 changed files with 33423 additions and 28955 deletions

View File

@@ -1,15 +1,16 @@
[package]
name = "auth"
version = "0.1.0"
edition = "2024"
edition.workspace = true
[dependencies]
config = { workspace = true }
async-trait = { workspace = true }
domain = { workspace = true }
anyhow = { workspace = true }
chrono = { workspace = true }
chrono = { workspace = true, features = ["clock"] }
uuid = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
jsonwebtoken = "9"
argon2 = { version = "0.5", features = ["std"] }
rand_core = { version = "0.6", features = ["getrandom"] }
serde = { workspace = true, features = ["derive"] }
jsonwebtoken = { workspace = true }
argon2 = { workspace = true, features = ["std"] }
rand_core = { workspace = true, features = ["getrandom"] }

View File

@@ -22,19 +22,17 @@ pub struct AuthConfig {
}
impl AuthConfig {
pub fn from_env() -> anyhow::Result<Self> {
let secret = std::env::var("JWT_SECRET")
.map_err(|_| anyhow::anyhow!("JWT_SECRET env var is required"))?;
pub fn from_config(config: &config::AuthConfig) -> anyhow::Result<Self> {
let secret = config
.jwt_secret
.clone()
.ok_or_else(|| anyhow::anyhow!("JWT_SECRET env var is required"))?;
if secret.is_empty() {
anyhow::bail!("JWT_SECRET must not be empty");
}
let ttl_seconds = std::env::var("JWT_TTL_SECONDS")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(900u64);
Ok(Self {
secret,
ttl_seconds,
ttl_seconds: config.jwt_ttl_seconds,
})
}
}
@@ -107,11 +105,13 @@ impl PasswordHasher for Argon2PasswordHasher {
}
}
pub fn create() -> anyhow::Result<(
pub fn create(
config: &config::AuthConfig,
) -> anyhow::Result<(
std::sync::Arc<dyn domain::ports::AuthService>,
std::sync::Arc<dyn domain::ports::PasswordHasher>,
)> {
let config = AuthConfig::from_env()?;
let config = AuthConfig::from_config(config)?;
Ok((
std::sync::Arc::new(JwtAuthService::new(config)),
std::sync::Arc::new(Argon2PasswordHasher),