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,
|
"id": user.id,
|
||||||
"name": user.name,
|
"name": user.name,
|
||||||
"email": user.email,
|
"email": user.email,
|
||||||
"phone": user.phone,
|
"phone": null,
|
||||||
"status": user.status,
|
"status": user.status,
|
||||||
"email_verified": user.email_verified,
|
"email_verified": user.email_verified,
|
||||||
"created_at": user.created_at,
|
"created_at": user.created_at,
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,6 @@ async fn register(
|
||||||
let user = UserRepository::create(&state.pool, CreateUserPayload {
|
let user = UserRepository::create(&state.pool, CreateUserPayload {
|
||||||
name: full_name,
|
name: full_name,
|
||||||
email: email.clone(),
|
email: email.clone(),
|
||||||
phone: payload.phone.filter(|p| !p.trim().is_empty()),
|
|
||||||
password_hash,
|
password_hash,
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
|
@ -271,7 +270,7 @@ async fn register(
|
||||||
Ok((StatusCode::CREATED, Json(RegisterResponse {
|
Ok((StatusCode::CREATED, Json(RegisterResponse {
|
||||||
user_id: user.id.to_string(),
|
user_id: user.id.to_string(),
|
||||||
email: user.email,
|
email: user.email,
|
||||||
phone: user.phone,
|
phone: None,
|
||||||
name: user.name.unwrap_or_default(),
|
name: user.name.unwrap_or_default(),
|
||||||
status: user.status,
|
status: user.status,
|
||||||
email_verified: user.email_verified,
|
email_verified: user.email_verified,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ pub struct User {
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub password_hash: String,
|
pub password_hash: String,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub phone: Option<String>,
|
|
||||||
pub email_verified: bool,
|
pub email_verified: bool,
|
||||||
pub phone_verified: bool,
|
pub phone_verified: bool,
|
||||||
pub status: String, // ACTIVE, SUSPENDED, BANNED
|
pub status: String, // ACTIVE, SUSPENDED, BANNED
|
||||||
|
|
@ -29,7 +28,6 @@ pub struct User {
|
||||||
pub struct CreateUserPayload {
|
pub struct CreateUserPayload {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub phone: Option<String>,
|
|
||||||
pub password_hash: String,
|
pub password_hash: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,10 +49,10 @@ impl UserRepository {
|
||||||
pub async fn create(pool: &PgPool, payload: CreateUserPayload) -> Result<User, sqlx::Error> {
|
pub async fn create(pool: &PgPool, payload: CreateUserPayload) -> Result<User, sqlx::Error> {
|
||||||
let user = sqlx::query_as::<_, User>(
|
let user = sqlx::query_as::<_, User>(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO users (name, email, phone, password_hash, email_verified, phone_verified)
|
INSERT INTO users (name, email, password_hash, email_verified, phone_verified)
|
||||||
VALUES ($1, $2, $3, $4, false, false)
|
VALUES ($1, $2, $3, false, false)
|
||||||
RETURNING
|
RETURNING
|
||||||
id, email, password_hash, name, phone,
|
id, email, password_hash, name,
|
||||||
email_verified, phone_verified, status,
|
email_verified, phone_verified, status,
|
||||||
email_verification_token, email_verification_expires_at,
|
email_verification_token, email_verification_expires_at,
|
||||||
reset_password_token, reset_password_expires_at,
|
reset_password_token, reset_password_expires_at,
|
||||||
|
|
@ -63,7 +61,6 @@ impl UserRepository {
|
||||||
)
|
)
|
||||||
.bind(&payload.name)
|
.bind(&payload.name)
|
||||||
.bind(payload.email.to_lowercase())
|
.bind(payload.email.to_lowercase())
|
||||||
.bind(payload.phone)
|
|
||||||
.bind(payload.password_hash)
|
.bind(payload.password_hash)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -74,7 +71,7 @@ impl UserRepository {
|
||||||
pub async fn get_by_email(pool: &PgPool, email: &str) -> Result<User, sqlx::Error> {
|
pub async fn get_by_email(pool: &PgPool, email: &str) -> Result<User, sqlx::Error> {
|
||||||
sqlx::query_as::<_, User>(
|
sqlx::query_as::<_, User>(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, email, password_hash, name, phone,
|
SELECT id, email, password_hash, name,
|
||||||
email_verified, phone_verified, status,
|
email_verified, phone_verified, status,
|
||||||
email_verification_token, email_verification_expires_at,
|
email_verification_token, email_verification_expires_at,
|
||||||
reset_password_token, reset_password_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> {
|
pub async fn get_by_id(pool: &PgPool, id: Uuid) -> Result<User, sqlx::Error> {
|
||||||
sqlx::query_as::<_, User>(
|
sqlx::query_as::<_, User>(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, email, password_hash, name, phone,
|
SELECT id, email, password_hash, name,
|
||||||
email_verified, phone_verified, status,
|
email_verified, phone_verified, status,
|
||||||
email_verification_token, email_verification_expires_at,
|
email_verification_token, email_verification_expires_at,
|
||||||
reset_password_token, reset_password_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> {
|
pub async fn get_by_verification_token(pool: &PgPool, token: &str) -> Result<User, sqlx::Error> {
|
||||||
sqlx::query_as::<_, User>(
|
sqlx::query_as::<_, User>(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, email, password_hash, name, phone,
|
SELECT id, email, password_hash, name,
|
||||||
email_verified, phone_verified, status,
|
email_verified, phone_verified, status,
|
||||||
email_verification_token, email_verification_expires_at,
|
email_verification_token, email_verification_expires_at,
|
||||||
reset_password_token, reset_password_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> {
|
pub async fn get_by_reset_token(pool: &PgPool, token: &str) -> Result<User, sqlx::Error> {
|
||||||
sqlx::query_as::<_, User>(
|
sqlx::query_as::<_, User>(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, email, password_hash, name, phone,
|
SELECT id, email, password_hash, name,
|
||||||
email_verified, phone_verified, status,
|
email_verified, phone_verified, status,
|
||||||
email_verification_token, email_verification_expires_at,
|
email_verification_token, email_verification_expires_at,
|
||||||
reset_password_token, reset_password_expires_at,
|
reset_password_token, reset_password_expires_at,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue