From 43603fe66f51794ff8e012d9fa19aed738d1b8e8 Mon Sep 17 00:00:00 2001 From: Kodjo Sossouvi Date: Mon, 10 Nov 2025 15:54:05 +0100 Subject: [PATCH] Added auto admin creation --- src/myauth/factory.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/myauth/factory.py b/src/myauth/factory.py index c10ace0..5b12597 100644 --- a/src/myauth/factory.py +++ b/src/myauth/factory.py @@ -59,6 +59,7 @@ def create_sqlite_auth_service(db_path: str, def create_auth_app_for_sqlite(db_path: str, jwt_secret: str, + create_admin_user: bool = True, email_service: Optional[EmailService] = None): """ 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 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 communication and functionalities during authentication. :return: An application router configured for handling authentication API routes. """ 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 return create_auth_app(auth_service) 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.") def create_auth_app_for_postgresql(postgresql_url="mongodb://localhost:27017", - username="admin", - password="password", - jwt_secret="THIS_NEEDS_TO_BE_CHANGED"): + username="admin", + password="password", + jwt_secret="THIS_NEEDS_TO_BE_CHANGED"): raise NotImplementedError("PostgreSQL support is not yet implemented.")