Added auto admin creation

This commit is contained in:
2025-11-10 15:54:05 +01:00
parent ea7cf786cb
commit 43603fe66f

View File

@@ -59,6 +59,7 @@ def create_sqlite_auth_service(db_path: str,
def create_auth_app_for_sqlite(db_path: str, def create_auth_app_for_sqlite(db_path: str,
jwt_secret: str, jwt_secret: str,
create_admin_user: bool = True,
email_service: Optional[EmailService] = None): email_service: Optional[EmailService] = None):
""" """
Creates an application router designed to use with an SQLite database backend. Creates an application router designed to use with an SQLite database backend.
@@ -69,22 +70,25 @@ def create_auth_app_for_sqlite(db_path: str,
:param db_path: Path to the SQLite database file. :param db_path: Path to the SQLite database file.
:param jwt_secret: A secret string used for signing and verifying JWT tokens. :param jwt_secret: A secret string used for signing and verifying JWT tokens.
:param create_admin_user: Create an admin user if necessary.
:param email_service: An optional email service instance for managing email-related :param email_service: An optional email service instance for managing email-related
communication and functionalities during authentication. communication and functionalities during authentication.
:return: An application router configured for handling authentication API routes. :return: An application router configured for handling authentication API routes.
""" """
auth_service = create_sqlite_auth_service(db_path, jwt_secret, email_service) auth_service = create_sqlite_auth_service(db_path, jwt_secret, email_service)
if create_admin_user:
auth_service.create_admin_if_needed()
from .api.routes import create_auth_app from .api.routes import create_auth_app
return create_auth_app(auth_service) return create_auth_app(auth_service)
def create_auth_app_for_mongodb(mongodb_url="mongodb://localhost:27017", def create_auth_app_for_mongodb(mongodb_url="mongodb://localhost:27017",
jwt_secret="THIS_NEEDS_TO_BE_CHANGED"): jwt_secret="THIS_NEEDS_TO_BE_CHANGED"):
raise NotImplementedError("MongoDB support is not yet implemented.") raise NotImplementedError("MongoDB support is not yet implemented.")
def create_auth_app_for_postgresql(postgresql_url="mongodb://localhost:27017", def create_auth_app_for_postgresql(postgresql_url="mongodb://localhost:27017",
username="admin", username="admin",
password="password", password="password",
jwt_secret="THIS_NEEDS_TO_BE_CHANGED"): jwt_secret="THIS_NEEDS_TO_BE_CHANGED"):
raise NotImplementedError("PostgreSQL support is not yet implemented.") raise NotImplementedError("PostgreSQL support is not yet implemented.")