Fix: Check for any existing user, not just admin role

This commit is contained in:
Motoko
2026-03-30 16:45:13 +00:00
parent 6c7617f1b5
commit c2b673fdd3

View File

@@ -80,15 +80,15 @@ async def _create_initial_admin():
return
async with AsyncSessionLocal() as session:
# Check if admin already exists
# Check if username already exists (any role)
result = await session.execute(
text("SELECT id FROM agents WHERE username = :username AND role = 'admin'"),
text("SELECT id, role FROM agents WHERE username = :username"),
{"username": settings.INITIAL_ADMIN_USERNAME}
)
existing = result.fetchone()
if existing:
return # Admin already exists
return # Username already taken, skip creation
# Create admin user with bcrypt hash
password_hash = bcrypt.hashpw(