Files
imphnen-backend-service/imphnen-iam/src/auth/infrastructure/http/routes.rs
T
asepharyana c6ed5c5c19 fix(dimentorin): verify-email validates OTP before activating user
- new app_otp_cache table + OtpCache entity (ResourceEnum::OtpCache)
- PostgresOtpRepository upsert/find/delete keyed by email
- register/resend persist otp_hash+expiry after email sent (no orphan OTP)
- verify_email validates via OtpManager::validate_otp_hash, single-use delete
- 8 unit tests pass, e2e verified: wrong OTP 400, correct OTP 200
2026-08-04 23:35:34 +07:00

39 lines
1.5 KiB
Rust

use super::handlers::{
post_forgot_password, post_login, post_login_mentor, post_new_password,
post_refresh_token, post_register, post_resend_otp, post_verify_email,
};
use crate::auth::application::AuthServiceImpl;
use crate::auth::domain::AuthService;
use crate::auth::infrastructure::PostgresOtpRepository;
use crate::roles::infrastructure::persistence::PostgresRoleRepository;
use crate::users::infrastructure::persistence::PostgresUserRepository;
use axum::{Extension, Router, routing::post};
use imphnen_libs::AppState;
use sea_orm::DatabaseConnection;
use std::sync::Arc;
pub fn auth_public_routes(_db: DatabaseConnection, state: Arc<AppState>) -> Router {
let user_repo = Arc::new(PostgresUserRepository::new(
state.postgres_connection.conn.clone(),
));
let role_repo = Arc::new(PostgresRoleRepository::new(
state.postgres_connection.conn.clone(),
));
let otp_repo = Arc::new(PostgresOtpRepository::new(
state.postgres_connection.conn.clone(),
));
let auth_service: Arc<dyn AuthService> =
Arc::new(AuthServiceImpl::new(user_repo, role_repo, otp_repo));
Router::new()
.route("/auth/login", post(post_login))
.route("/auth/login-mentor", post(post_login_mentor))
.route("/auth/register", post(post_register))
.route("/auth/verify-email", post(post_verify_email))
.route("/auth/send-otp", post(post_resend_otp))
.route("/auth/forgot", post(post_forgot_password))
.route("/auth/new-password", post(post_new_password))
.route("/auth/refresh", post(post_refresh_token))
.layer(Extension(auth_service))
.layer(Extension((*state).clone()))
}