fix(auth): accept both full_name and first_name+last_name for backward compatibility
RegisterPayload now accepts: - full_name (single field, for old frontend clients) - first_name + last_name (new format) Error returned only if none of these are provided.
This commit is contained in:
parent
2861e7a5fe
commit
63eb27a160
2 changed files with 44 additions and 3 deletions
|
|
@ -35,8 +35,12 @@ pub fn router() -> Router<AppState> {
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct RegisterPayload {
|
pub struct RegisterPayload {
|
||||||
pub first_name: String,
|
#[serde(default)]
|
||||||
pub last_name: String,
|
pub first_name: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub last_name: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub full_name: Option<String>,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub phone: Option<String>,
|
pub phone: Option<String>,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
|
|
@ -198,7 +202,11 @@ async fn register(
|
||||||
let password_hash = hash_password(&payload.password)
|
let password_hash = hash_password(&payload.password)
|
||||||
.map_err(|e| err(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string(), "INTERNAL_ERROR"))?;
|
.map_err(|e| err(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string(), "INTERNAL_ERROR"))?;
|
||||||
|
|
||||||
let full_name = format!("{} {}", payload.first_name.trim(), payload.last_name.trim()).trim().to_string();
|
let full_name = match (&payload.first_name, &payload.last_name, &payload.full_name) {
|
||||||
|
(Some(fn_), Some(ln_), _) => format!("{} {}", fn_.trim(), ln_.trim()).trim().to_string(),
|
||||||
|
(_, _, Some(fn_)) => fn_.trim().to_string(),
|
||||||
|
_ => return Err(err(StatusCode::UNPROCESSABLE_ENTITY, "first_name and last_name are required", "VALIDATION_ERROR")),
|
||||||
|
};
|
||||||
|
|
||||||
let user = UserRepository::create(&state.pool, CreateUserPayload {
|
let user = UserRepository::create(&state.pool, CreateUserPayload {
|
||||||
name: full_name,
|
name: full_name,
|
||||||
|
|
|
||||||
33
k8s-migration-job.yaml
Normal file
33
k8s-migration-job.yaml
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: Job
|
||||||
|
metadata:
|
||||||
|
name: nxtgauge-db-migrate
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: nxtgauge-db-migrate
|
||||||
|
spec:
|
||||||
|
ttlSecondsAfterFinished: 300
|
||||||
|
backoffLimit: 3
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: nxtgauge-db-migrate
|
||||||
|
spec:
|
||||||
|
restartPolicy: OnFailure
|
||||||
|
containers:
|
||||||
|
- name: migrate
|
||||||
|
image: ghcr.io/traceworks2023/nxtgauge-db-migrate:high-performance-latest
|
||||||
|
imagePullPolicy: Always
|
||||||
|
envFrom:
|
||||||
|
- secretRef:
|
||||||
|
name: nxtgauge-backend-rust-secrets
|
||||||
|
env:
|
||||||
|
- name: MIGRATIONS_DIR
|
||||||
|
value: "/migrations"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "64Mi"
|
||||||
|
cpu: "50m"
|
||||||
|
limits:
|
||||||
|
memory: "256Mi"
|
||||||
|
cpu: "500m"
|
||||||
Loading…
Add table
Reference in a new issue