fix: guard created_by FK in user creation handler

The auth identity user_id (from owner_id scope) may not match any
user row in the DB, causing a FK violation on the created_by column.
Check that the referenced user exists before setting created_by.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
Illia Polosukhin
2026-03-26 10:06:32 -07:00
co-authored by Claude Opus 4.6
parent 27c6d1d6b7
commit 6cc77fe162
+4 -1
View File
@@ -61,7 +61,10 @@ pub async fn users_create_handler(
created_at: now,
updated_at: now,
last_login_at: None,
created_by: Some(user.user_id.clone()),
created_by: match store.get_user(&user.user_id).await {
Ok(Some(_)) => Some(user.user_id.clone()),
_ => None,
},
metadata: serde_json::json!({}),
};