fix(auth): remove phone from INSERT and User struct since column doesn't exist
- Remove phone from INSERT INTO users (users table has no phone column) - Remove phone from User struct and CreateUserPayload - Return null for phone in API responses - Keep phone field in RegisterPayload for backward compat (just not persisted)
This commit is contained in:
parent
1d50d21f00
commit
3432d67cc4
3 changed files with 10 additions and 14 deletions
|
|
@ -96,7 +96,7 @@ async fn get_submission(
|
|||
"id": user.id,
|
||||
"name": user.name,
|
||||
"email": user.email,
|
||||
"phone": user.phone,
|
||||
"phone": null,
|
||||
"status": user.status,
|
||||
"email_verified": user.email_verified,
|
||||
"created_at": user.created_at,
|
||||
|
|
|
|||
|
|
@ -214,7 +214,6 @@ async fn register(
|
|||
let user = UserRepository::create(&state.pool, CreateUserPayload {
|
||||
name: full_name,
|
||||
email: email.clone(),
|
||||
phone: payload.phone.filter(|p| !p.trim().is_empty()),
|
||||
password_hash,
|
||||
})
|
||||
.await
|
||||
|
|
@ -271,8 +270,8 @@ async fn register(
|
|||
Ok((StatusCode::CREATED, Json(RegisterResponse {
|
||||
user_id: user.id.to_string(),
|
||||
email: user.email,
|
||||
phone: user.phone,
|
||||
name: user.name.unwrap_or_default(),
|
||||
phone: None,
|
||||
name: user.name.unwrap_or_default(),
|
||||
status: user.status,
|
||||
email_verified: user.email_verified,
|
||||
created_at: user.created_at.to_rfc3339(),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ pub struct User {
|
|||
pub email: String,
|
||||
pub password_hash: String,
|
||||
pub name: Option<String>,
|
||||
pub phone: Option<String>,
|
||||
pub email_verified: bool,
|
||||
pub phone_verified: bool,
|
||||
pub status: String, // ACTIVE, SUSPENDED, BANNED
|
||||
|
|
@ -29,7 +28,6 @@ pub struct User {
|
|||
pub struct CreateUserPayload {
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
pub phone: Option<String>,
|
||||
pub password_hash: String,
|
||||
}
|
||||
|
||||
|
|
@ -51,10 +49,10 @@ impl UserRepository {
|
|||
pub async fn create(pool: &PgPool, payload: CreateUserPayload) -> Result<User, sqlx::Error> {
|
||||
let user = sqlx::query_as::<_, User>(
|
||||
r#"
|
||||
INSERT INTO users (name, email, phone, password_hash, email_verified, phone_verified)
|
||||
VALUES ($1, $2, $3, $4, false, false)
|
||||
INSERT INTO users (name, email, password_hash, email_verified, phone_verified)
|
||||
VALUES ($1, $2, $3, false, false)
|
||||
RETURNING
|
||||
id, email, password_hash, name, phone,
|
||||
id, email, password_hash, name,
|
||||
email_verified, phone_verified, status,
|
||||
email_verification_token, email_verification_expires_at,
|
||||
reset_password_token, reset_password_expires_at,
|
||||
|
|
@ -63,7 +61,6 @@ impl UserRepository {
|
|||
)
|
||||
.bind(&payload.name)
|
||||
.bind(payload.email.to_lowercase())
|
||||
.bind(payload.phone)
|
||||
.bind(payload.password_hash)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
|
|
@ -74,7 +71,7 @@ impl UserRepository {
|
|||
pub async fn get_by_email(pool: &PgPool, email: &str) -> Result<User, sqlx::Error> {
|
||||
sqlx::query_as::<_, User>(
|
||||
r#"
|
||||
SELECT id, email, password_hash, name, phone,
|
||||
SELECT id, email, password_hash, name,
|
||||
email_verified, phone_verified, status,
|
||||
email_verification_token, email_verification_expires_at,
|
||||
reset_password_token, reset_password_expires_at,
|
||||
|
|
@ -91,7 +88,7 @@ impl UserRepository {
|
|||
pub async fn get_by_id(pool: &PgPool, id: Uuid) -> Result<User, sqlx::Error> {
|
||||
sqlx::query_as::<_, User>(
|
||||
r#"
|
||||
SELECT id, email, password_hash, name, phone,
|
||||
SELECT id, email, password_hash, name,
|
||||
email_verified, phone_verified, status,
|
||||
email_verification_token, email_verification_expires_at,
|
||||
reset_password_token, reset_password_expires_at,
|
||||
|
|
@ -148,7 +145,7 @@ impl UserRepository {
|
|||
pub async fn get_by_verification_token(pool: &PgPool, token: &str) -> Result<User, sqlx::Error> {
|
||||
sqlx::query_as::<_, User>(
|
||||
r#"
|
||||
SELECT id, email, password_hash, name, phone,
|
||||
SELECT id, email, password_hash, name,
|
||||
email_verified, phone_verified, status,
|
||||
email_verification_token, email_verification_expires_at,
|
||||
reset_password_token, reset_password_expires_at,
|
||||
|
|
@ -196,7 +193,7 @@ impl UserRepository {
|
|||
pub async fn get_by_reset_token(pool: &PgPool, token: &str) -> Result<User, sqlx::Error> {
|
||||
sqlx::query_as::<_, User>(
|
||||
r#"
|
||||
SELECT id, email, password_hash, name, phone,
|
||||
SELECT id, email, password_hash, name,
|
||||
email_verified, phone_verified, status,
|
||||
email_verification_token, email_verification_expires_at,
|
||||
reset_password_token, reset_password_expires_at,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue