diff --git a/server/src/auth/handlers/register.rs b/server/src/auth/handlers/register.rs index c4692d1..9d0d63d 100644 --- a/server/src/auth/handlers/register.rs +++ b/server/src/auth/handlers/register.rs @@ -1,7 +1,10 @@ +// src/auth/handlers/register.rs + use bcrypt::{hash, DEFAULT_COST}; use tonic::{Request, Response, Status}; -use uuid::Uuid; -use crate::{auth::{models::{RegisterRequest, AuthResponse, AuthError}, db::PgPool}}; +use common::proto::multieko2::auth::{auth_service_server, RegisterRequest, AuthResponse}; +use crate::db::PgPool; +use crate::auth::models::AuthError; pub struct AuthService { pool: PgPool, @@ -14,11 +17,11 @@ impl AuthService { } #[tonic::async_trait] -impl multieko2::auth::auth_service_server::AuthService for AuthService { +impl auth_service_server::AuthService for AuthService { async fn register( &self, - request: Request, - ) -> Result, Status> { + request: Request, + ) -> Result, Status> { let payload = request.into_inner(); // Validate passwords match @@ -51,10 +54,10 @@ impl multieko2::auth::auth_service_server::AuthService for AuthService { } })?; - Ok(Response::new(multieko2::auth::AuthResponse { + Ok(Response::new(AuthResponse { id: user.id.to_string(), username: user.username, - email: user.email, + email: user.email.unwrap_or_default(), role: user.role, })) } diff --git a/server/src/auth/models.rs b/server/src/auth/models.rs index 51fee0e..ca64358 100644 --- a/server/src/auth/models.rs +++ b/server/src/auth/models.rs @@ -1,26 +1,19 @@ +// src/auth/models.rs + use serde::{Deserialize, Serialize}; -use uuid::Uuid; use validator::Validate; #[derive(Debug, Validate, Deserialize)] pub struct RegisterRequest { - #[validate(length(min = 3, max = 30))] + #[validate(length(min = 1, max = 30))] pub username: String, #[validate(email)] pub email: String, - #[validate(length(min = 8))] + #[validate(length(min = 1))] pub password: String, pub password_confirmation: String, } -#[derive(Debug, Serialize)] -pub struct AuthResponse { - pub id: Uuid, - pub username: String, - pub email: String, - pub role: String, -} - #[derive(Debug, thiserror::Error)] pub enum AuthError { #[error("Passwords do not match")] diff --git a/server/src/db.rs b/server/src/db.rs index 4840945..e4faa07 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -1,5 +1,7 @@ // src/db.rs -use sqlx::postgres::{PgPool, PgPoolOptions}; + +use sqlx::postgres::PgPoolOptions; +pub use sqlx::postgres::PgPool; use std::time::Duration; use tracing::info;