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
|
return
|
||||||
|
|
||||||
async with AsyncSessionLocal() as session:
|
async with AsyncSessionLocal() as session:
|
||||||
# Check if admin already exists
|
# Check if username already exists (any role)
|
||||||
result = await session.execute(
|
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}
|
{"username": settings.INITIAL_ADMIN_USERNAME}
|
||||||
)
|
)
|
||||||
existing = result.fetchone()
|
existing = result.fetchone()
|
||||||
|
|
||||||
if existing:
|
if existing:
|
||||||
return # Admin already exists
|
return # Username already taken, skip creation
|
||||||
|
|
||||||
# Create admin user with bcrypt hash
|
# Create admin user with bcrypt hash
|
||||||
password_hash = bcrypt.hashpw(
|
password_hash = bcrypt.hashpw(
|
||||||
|
|||||||
Reference in New Issue
Block a user