Skip to content

Commit 0857e41

Browse files
committed
basic auth
1 parent ae261dd commit 0857e41

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

code_assistant/constants/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
GENERATED_APPS_DIR = os.getcwd() + "/" + os.getenv('CA_GENERATED_APPS_DIR', 'generated_apps')
44
MODEL = os.getenv('CA_MODEL', 'gpt-4o-2024-08-06')
55
#MODEL = os.getenv('CA_MODEL', 'openai/o1-preview')
6-
#MODEL = os.getenv('CA_MODEL', 'claude-3-5-sonnet-20240620')
6+
#MODEL = os.getenv('CA_MODEL', 'claude-3-5-sonnet-20240620')
7+
USER = os.getenv('CA_USER')
8+
PASSWORD = os.getenv('CA_PASSWORD')

code_assistant/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
from code_assistant.constants.css_text import css_text
1212
from code_assistant.constants.post_message_listener_src import post_message_listener_src
1313
from code_assistant.util.file_util import get_mount_from_project
14-
from code_assistant.constants.config import GENERATED_APPS_DIR
15-
from code_assistant.constants.config import GENERATED_APPS_DIR
14+
from code_assistant.constants.config import GENERATED_APPS_DIR, USER, PASSWORD
1615

1716
from importlib.resources import files
1817

@@ -49,7 +48,14 @@
4948

5049
iframe_post_message_script = Script(post_message_listener_src, type="module")
5150

52-
app, rt = fast_app(hdrs=(tlink, dlink, css, scrollScript, plink, iframe_post_message_script), routes=app_routes)
51+
52+
middleware = []
53+
if USER is not None and PASSWORD is not None:
54+
print("Setting up basic auth")
55+
auth = user_pwd_auth({USER: PASSWORD}, skip=[r'/favicon\.ico', r'/static/.*', r'.*\.css'])
56+
middleware.append(auth)
57+
58+
app, rt = fast_app(hdrs=(tlink, dlink, css, scrollScript, plink, iframe_post_message_script), routes=app_routes, middleware=middleware)
5359

5460
#setup_toasts(app) work around toast bug until fasthtml 5.2 ships
5561
app.hdrs += (Style(toast_css), Script(toast_js, type="module"))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "code-assistant"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "A FastHTML app that builds FastHTML apps"
55
authors = [{ name = "phact", email = "estevezsebastian@gmail.com" }]
66
readme = "README.md"

0 commit comments

Comments
 (0)