Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Settings(BaseSettings):
BREVO_EMAIL_FROM_ADDRESS: str = os.getenv("BREVO_EMAIL_FROM_ADDRESS", "noreply@example.com")
BREVO_EMAIL_FROM_NAME: str = os.getenv("BREVO_EMAIL_FROM_NAME", "BookLib")

app_base_url: str = os.getenv("APP_BASE_URL", "")
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it possible to extract the base url from another place instead of a new ENV var?


DEBUG: bool = os.getenv("DEBUG", "false").lower() == "true"
admin_users_env: str = Field(default=os.getenv("ADMIN_USERS", ""), repr=False)
admin_users: set[str] = set()
Expand Down
13 changes: 11 additions & 2 deletions routes/auth.py
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add import of settings

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy.orm import Session

from core.auth import create_session, get_authenticated_user
from core.config import settings
from core.email import send_password_reset_email, send_verification_email
from core.security import (
generate_password_reset_token,
Expand Down Expand Up @@ -92,7 +93,11 @@ def _handle_register(
if not created_user:
return None, "Error creating user. Please try again."

base_url = str(request.base_url).rstrip("/")
base_url = (
settings.app_base_url.rstrip("/")
if settings.app_base_url
else str(request.base_url).rstrip("/")
)
email_sent = send_verification_email(
created_user.email, created_user.username, verification_token, base_url
)
Expand Down Expand Up @@ -262,7 +267,11 @@ async def handle_forgot_password(
if not set_password_reset_token(db, user, token):
logger.error(f"Failed to save reset token to DB for {user.email}")
else:
base_url = str(request.base_url).rstrip("/")
base_url = (
settings.app_base_url.rstrip("/")
if settings.app_base_url
else str(request.base_url).rstrip("/")
)
email_sent = send_password_reset_email(user.email, user.username, token, base_url)
if not email_sent:
logger.warning(f"Failed attempt to send reset email for {user.email}.")
Expand Down