driver / scripts /seed_admin.py
bevisssssss's picture
fix: recover from expired admin token instead of showing a load error
79dca2e
Raw History Blame Contribute Delete
710 Bytes
"""Create or update the initial admin account."""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from server.db import init_db, create_admin, get_admin
from server.auth import hash_password
def main():
init_db()
username = os.getenv("ADMIN_USER", "admin")
password = os.getenv("ADMIN_PASS", "admin123")
if get_admin(username):
print(f"Admin '{username}' already exists, skipping.")
return
pw_hash = hash_password(password)
if create_admin(username, pw_hash):
print(f"Admin '{username}' created successfully.")
else:
print(f"Failed to create admin '{username}'.")
if __name__ == "__main__":
main()