Updated to myauth2.0

Admin user is automatically created
This commit is contained in:
2025-10-30 20:13:11 +01:00
parent 8a49497a61
commit b5c1c15198
4 changed files with 22 additions and 4 deletions

View File

@@ -176,4 +176,9 @@ Predefined login page that provides a UI template ready for integration.
## Exceptions ## Exceptions
No custom exceptions defined yet. (Placeholder for future use.) No custom exceptions defined yet. (Placeholder for future use.)
```
## Relase History
* 0.1.0 : First release
* 0.2.0 : Updated to myauth 0.2.0

View File

@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "myfasthtml" name = "myfasthtml"
version = "0.1.0" version = "0.2.0"
description = "Set of tools to quickly create HTML pages using FastHTML." description = "Set of tools to quickly create HTML pages using FastHTML."
readme = "README.md" readme = "README.md"
authors = [ authors = [

View File

@@ -0,0 +1,4 @@
import myfasthtml.auth
import myfasthtml.controls
import myfasthtml.core
import myfasthtml.icons

View File

@@ -7,6 +7,7 @@ from fasthtml.components import Link, Script
from starlette.responses import Response from starlette.responses import Response
from myfasthtml.auth.routes import setup_auth_routes from myfasthtml.auth.routes import setup_auth_routes
from myfasthtml.auth.utils import create_auth_beforeware
def get_asset_path(filename): def get_asset_path(filename):
@@ -24,7 +25,10 @@ def get_asset_content(filename):
return get_asset_path(filename).read_text() 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 Creates and configures a FastHtml application with optional support for daisyUI themes and
authentication routes. 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. :param daisyui: Flag to enable or disable inclusion of daisyUI-related assets for styling.
Defaults to False. Defaults to False.
:type daisyui: Optional[bool] :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. :param mount_auth_app: Flag to enable or disable mounting of authentication routes.
Defaults to False. 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"), 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 # remove the global static files routes
static_route_exts_get = app.routes.pop(0) static_route_exts_get = app.routes.pop(0)