From b5c1c1519877c014dc1113778305dab2bbf1c55b Mon Sep 17 00:00:00 2001 From: Kodjo Sossouvi Date: Thu, 30 Oct 2025 20:13:11 +0100 Subject: [PATCH] Updated to myauth2.0 Admin user is automatically created --- README.md | 7 ++++++- pyproject.toml | 2 +- src/myfasthtml/__init__.py | 4 ++++ src/myfasthtml/myfastapp.py | 13 +++++++++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3ac2fb5..1324e7e 100644 --- a/README.md +++ b/README.md @@ -176,4 +176,9 @@ Predefined login page that provides a UI template ready for integration. ## Exceptions No custom exceptions defined yet. (Placeholder for future use.) -``` \ No newline at end of file + + +## Relase History + +* 0.1.0 : First release +* 0.2.0 : Updated to myauth 0.2.0 diff --git a/pyproject.toml b/pyproject.toml index c82fa30..17ded10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "myfasthtml" -version = "0.1.0" +version = "0.2.0" description = "Set of tools to quickly create HTML pages using FastHTML." readme = "README.md" authors = [ diff --git a/src/myfasthtml/__init__.py b/src/myfasthtml/__init__.py index e69de29..b529bd9 100644 --- a/src/myfasthtml/__init__.py +++ b/src/myfasthtml/__init__.py @@ -0,0 +1,4 @@ +import myfasthtml.auth +import myfasthtml.controls +import myfasthtml.core +import myfasthtml.icons diff --git a/src/myfasthtml/myfastapp.py b/src/myfasthtml/myfastapp.py index cada01f..cccf3a1 100644 --- a/src/myfasthtml/myfastapp.py +++ b/src/myfasthtml/myfastapp.py @@ -7,6 +7,7 @@ from fasthtml.components import Link, Script from starlette.responses import Response from myfasthtml.auth.routes import setup_auth_routes +from myfasthtml.auth.utils import create_auth_beforeware def get_asset_path(filename): @@ -24,7 +25,10 @@ def get_asset_content(filename): return get_asset_path(filename).read_text() -def create_app(daisyui: Optional[bool] = False, mount_auth_app: Optional[bool] = False, **kwargs) -> Any: +def create_app(daisyui: Optional[bool] = False, + protect_routes: Optional[bool] = True, + mount_auth_app: Optional[bool] = False, + **kwargs) -> Any: """ Creates and configures a FastHtml application with optional support for daisyUI themes and authentication routes. @@ -32,6 +36,10 @@ def create_app(daisyui: Optional[bool] = False, mount_auth_app: Optional[bool] = :param daisyui: Flag to enable or disable inclusion of daisyUI-related assets for styling. Defaults to False. :type daisyui: Optional[bool] + + :param protect_routes: Flag to enable or disable routes protection based on authentication. + Defaults to True. + :type protect_routes: Optional[bool] :param mount_auth_app: Flag to enable or disable mounting of authentication routes. Defaults to False. @@ -51,7 +59,8 @@ def create_app(daisyui: Optional[bool] = False, mount_auth_app: Optional[bool] = Script(src="/myfasthtml/tailwindcss-browser@4.js"), ] - app, rt = fasthtml.fastapp.fast_app(hdrs=tuple(hdrs), **kwargs) + beforeware = create_auth_beforeware() if protect_routes else None + app, rt = fasthtml.fastapp.fast_app(before=beforeware, hdrs=tuple(hdrs), **kwargs) # remove the global static files routes static_route_exts_get = app.routes.pop(0)