Fix: Check for any existing user, not just admin role
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user