use sqlx::types::Json;
use sqlx::{Executor, Postgres, Row};
use crate::logic::user::AuthData;
pub async fn update_user_auth(
exec: impl Executor<'_, Database = Postgres>,
acct: &str,
auth_data: AuthData,
) -> Result<Option<()>, sqlx::Error> {
let result = sqlx::query(
r#"
update user_principal
set auth_data = $1
where acct = $2
returning acct
"#,
)
.bind(Json(auth_data))
.bind(acct)
.fetch_optional(exec)
.await?;
match result {
None => Ok(None),
Some(row) => {
row.try_get::<String, usize>(0)?;
Ok(Some(()))
}
}
}