This commit is contained in:
Matthew McPeak 2026-06-17 19:48:39 -04:00
parent 32825ba9e1
commit 93e66f1236
Signed by: McPeakML
GPG key ID: 3D64A2E70F58D07C

View file

@ -73,6 +73,15 @@ async fn main() -> anyhow::Result<()> {
.await? .await?
.unwrap_or(0); .unwrap_or(0);
if user_count == 0 { if user_count == 0 {
let (username, password) = match (
std::env::var("MERCURY_ADMIN_USER").ok().filter(|s| !s.is_empty()),
std::env::var("MERCURY_ADMIN_PASSWORD").ok().filter(|s| !s.is_empty()),
) {
(Some(u), Some(p)) => {
tracing::info!("creating first admin user from environment variables");
(u, p)
}
_ => {
println!("\nNo users found. Create the first admin account."); println!("\nNo users found. Create the first admin account.");
print!("Username: "); print!("Username: ");
io::stdout().flush()?; io::stdout().flush()?;
@ -91,6 +100,9 @@ async fn main() -> anyhow::Result<()> {
if password.is_empty() { if password.is_empty() {
anyhow::bail!("password cannot be empty"); anyhow::bail!("password cannot be empty");
} }
(username, password)
}
};
let hash = bcrypt::hash(&password, bcrypt::DEFAULT_COST)?; let hash = bcrypt::hash(&password, bcrypt::DEFAULT_COST)?;
sqlx::query( sqlx::query(