Refactor and enhance SurrealDB integration and resource management
- Updated `lib.rs` to selectively expose specific entities and services for better clarity. - Improved SurrealDB client initialization with detailed logging in `surrealdb/mod.rs`. - Enhanced resource definitions in `resource.rs` with additional utility methods for better resource management. - Refactored user data retrieval logic in `auth_middleware/mod.rs` for improved readability and efficiency. - Cleaned up middleware exports in `lib.rs` for clearer API surface. - Added detailed comments and documentation throughout the SurrealDB module for better maintainability. - Updated tests to ensure compatibility with new changes and improved structure. - Introduced new permissions module structure in `imphnen-utils` for future enhancements.
This commit is contained in:
@@ -2,7 +2,7 @@ use super::{
|
||||
AuthLoginRequestDto, AuthRefreshTokenRequestDto, AuthRegisterRequestDto,
|
||||
AuthResendOtpRequestDto, AuthVerifyEmailRequestDto,
|
||||
};
|
||||
use crate::{AppState, v1::AuthLoginResponsetDto};
|
||||
use crate::{AppState, v1::auth::AuthLoginResponsetDto};
|
||||
use crate::{AuthNewPasswordRequestDto, MessageResponseDto, ResponseSuccessDto};
|
||||
use axum::{Extension, Json, response::IntoResponse};
|
||||
use crate::v1::auth::auth_service::AuthServiceTrait;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::pin::Pin;
|
||||
use std::future::Future;
|
||||
use imphnen_utils as generate_otp;
|
||||
use imphnen_libs::enviroment;
|
||||
use super::{
|
||||
AuthLoginRequestDto, AuthLoginResponsetDto, AuthNewPasswordRequestDto,
|
||||
AuthRefreshTokenRequestDto, AuthRegisterRequestDto, AuthRepository,
|
||||
@@ -9,7 +11,7 @@ use crate::{
|
||||
AppState, ResourceEnum, ResponseSuccessDto, RolesEnum, RolesRepository,
|
||||
UsersDetailItemDto, UsersRepository, UsersSchema, common_response,
|
||||
decode_refresh_token, encode_access_token, encode_refresh_token,
|
||||
encode_reset_password_token, extract_email_token_async, generate_otp, get_iso_date,
|
||||
encode_reset_password_token, extract_email_token_async, get_iso_date,
|
||||
hash_password, make_thing, send_email, success_response, validate_request,
|
||||
verify_password,
|
||||
};
|
||||
@@ -475,7 +477,7 @@ impl AuthServiceTrait for AuthService {
|
||||
}
|
||||
};
|
||||
|
||||
let env = &crate::enviroment::ENV;
|
||||
let env = &enviroment::ENV;
|
||||
let fe_url = env.fe_url.clone();
|
||||
let message = format!(
|
||||
"You have requested a password reset. Please click the link below to continue: {fe_url}/auth/reset-password?token={token}"
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/// Google OAuth integration module
|
||||
pub mod google_oauth_controller;
|
||||
pub mod google_oauth_dto;
|
||||
pub mod google_oauth_service;
|
||||
pub mod google_oauth_service;
|
||||
|
||||
// Export only essential types and functions from Google OAuth submodules
|
||||
pub use google_oauth_controller::GoogleOauthController;
|
||||
@@ -7,20 +7,45 @@ pub mod auth_schema;
|
||||
pub mod auth_service;
|
||||
pub mod google;
|
||||
|
||||
pub use auth_dto::*;
|
||||
pub use auth_repository::*;
|
||||
pub use auth_schema::*;
|
||||
pub use auth_service::*;
|
||||
// Export only the essential types and functions from each submodule
|
||||
pub use auth_dto::{
|
||||
AuthLoginRequestDto,
|
||||
AuthLoginResponsetDto,
|
||||
AuthRegisterRequestDto,
|
||||
AuthResendOtpRequestDto,
|
||||
AuthVerifyEmailRequestDto,
|
||||
AuthNewPasswordRequestDto,
|
||||
AuthRefreshTokenRequestDto,
|
||||
TokenDto,
|
||||
UserCacheSchema,
|
||||
};
|
||||
|
||||
pub use auth_repository::AuthRepository;
|
||||
pub use imphnen_libs::AuthRepositoryTrait;
|
||||
pub use auth_schema::AuthOtpSchema;
|
||||
pub use auth_service::AuthServiceTrait;
|
||||
|
||||
// Export controller functions that are used in routing
|
||||
pub use auth_controller::{
|
||||
post_login,
|
||||
post_login_mentor,
|
||||
post_register,
|
||||
post_forgot_password,
|
||||
post_new_password,
|
||||
post_refresh_token,
|
||||
post_resend_otp,
|
||||
post_verify_email
|
||||
};
|
||||
|
||||
pub fn auth_router() -> Router {
|
||||
Router::new()
|
||||
.nest("/google", google::google_oauth_controller::GoogleOauthController::new().get_routes())
|
||||
.route("/forgot", post(auth_controller::post_forgot_password))
|
||||
.route("/login", post(auth_controller::post_login))
|
||||
.route("/login-mentor", post(auth_controller::post_login_mentor))
|
||||
.route("/new-password", post(auth_controller::post_new_password))
|
||||
.route("/refresh", post(auth_controller::post_refresh_token))
|
||||
.route("/register", post(auth_controller::post_register))
|
||||
.route("/send-otp", post(auth_controller::post_resend_otp))
|
||||
.route("/verify-email", post(auth_controller::post_verify_email))
|
||||
.route("/forgot", post(post_forgot_password))
|
||||
.route("/login", post(post_login))
|
||||
.route("/login-mentor", post(post_login_mentor))
|
||||
.route("/new-password", post(post_new_password))
|
||||
.route("/refresh", post(post_refresh_token))
|
||||
.route("/register", post(post_register))
|
||||
.route("/send-otp", post(post_resend_otp))
|
||||
.route("/verify-email", post(post_verify_email))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user