framework_cqrs_lib/cqrs/infra/authentication/
mod.rsuse std::sync::Arc;
use crate::cqrs::infra::token::services::jwt_hmac::JwtHMACTokenService;
use crate::cqrs::infra::token::services::jwt_hmac_encoder::JwtHMACEncoderTokenService;
use crate::cqrs::models::errors::{Error, ResultErr};
pub struct AuthenticationComponent {
pub jwt_token_decoder_service: Arc<JwtHMACTokenService>,
pub jwt_token_encoder_service: Arc<JwtHMACEncoderTokenService>,
}
impl AuthenticationComponent {
pub fn new() -> ResultErr<Self> {
let jwt_secret = std::env::var("JWT_SECRET")
.map_err(|_|
Error::Simple("env variable JWT_SECRET is not defined".to_string())
)?;
Ok(
Self {
jwt_token_decoder_service: Arc::new(JwtHMACTokenService::new(jwt_secret.clone())),
jwt_token_encoder_service: Arc::new(JwtHMACEncoderTokenService::new(jwt_secret)),
}
)
}
}