From 75eb9725ac04bf28930f34c31db451624a4623ba Mon Sep 17 00:00:00 2001
From: Kohaku-Blueleaf <59680068+KohakuBlueleaf@users.noreply.github.com>
Date: Sun, 5 Oct 2025 03:29:32 +0800
Subject: [PATCH] fix email verification
---
docker/nginx/default.conf | 34 ++++---
src/kohaku-hub-ui/src/pages/index.vue | 17 ++++
src/kohakuhub/auth/email.py | 130 ++++++++++++++++++++++++--
src/kohakuhub/auth/routes.py | 41 +++++++-
4 files changed, 199 insertions(+), 23 deletions(-)
diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf
index 66fc0b3..2fb2932 100644
--- a/docker/nginx/default.conf
+++ b/docker/nginx/default.conf
@@ -13,51 +13,63 @@ server {
# API PROXY RULES
#
# These specific locations are evaluated BEFORE the general SPA rule.
- # The order of these proxy rules matters.
+ # The order of these proxy rules matters - most specific first.
# =================================================================
- # 1. Standard API prefixes (highest priority for matching)
+ # 1. API endpoints (all routes under /api/)
+ # Covers: /api/auth/*, /api/repos/*, /api/models/*, /api/datasets/*,
+ # /api/spaces/*, /api/users/*, /api/organizations/*, /api/whoami-v2, etc.
location /api/ {
proxy_pass http://hub-api:48888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
}
+ # 2. Organization API endpoints (mounted at /org/)
+ # Covers: /org/create, /org/{name}, /org/{name}/members, /org/users/{username}/orgs
location /org/ {
proxy_pass http://hub-api:48888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
}
- # 2. Git LFS routes (critical for large file uploads/downloads)
- # Matches URLs like /kohaku/test-2.git/info/lfs/objects/batch
+ # 3. Git LFS endpoints
+ # Covers: /{type}s/{namespace}/{name}.git/info/lfs/* and /{namespace}/{name}.git/info/lfs/*
location ~ \.git/info/lfs/ {
proxy_pass http://hub-api:48888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ # Important for large file uploads
+ proxy_request_buffering off;
+ client_body_buffer_size 128k;
}
- # 3. File resolution routes (for downloads)
- # This is the most specific pattern and should be checked first.
- # Matches /models/user/repo/resolve/...
+ # 4. Public file resolution routes (no /api prefix)
+ # These are public-facing download endpoints
+ # Pattern: /{type}s/{namespace}/{name}/resolve/{revision}/{path}
location ~ ^/(models|datasets|spaces)/[^/]+/[^/]+/resolve/ {
proxy_pass http://hub-api:48888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
}
- # This is the legacy pattern.
- # Matches /user/repo/resolve/...
- # By placing it after the more specific rule above, we avoid conflicts.
+ # 5. Legacy public file resolution route (no /api prefix, no type prefix)
+ # Pattern: /{namespace}/{name}/resolve/{revision}/{path}
+ # Must come AFTER the specific routes to avoid catching frontend routes
location ~ ^/[^/]+/[^/]+/resolve/ {
proxy_pass http://hub-api:48888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
}
@@ -70,4 +82,4 @@ server {
location / {
try_files $uri $uri/ /index.html;
}
-}
\ No newline at end of file
+}
diff --git a/src/kohaku-hub-ui/src/pages/index.vue b/src/kohaku-hub-ui/src/pages/index.vue
index 6171564..9f0b320 100644
--- a/src/kohaku-hub-ui/src/pages/index.vue
+++ b/src/kohaku-hub-ui/src/pages/index.vue
@@ -208,12 +208,14 @@
diff --git a/src/kohakuhub/auth/email.py b/src/kohakuhub/auth/email.py
index 4abe4ae..6ad71a2 100644
--- a/src/kohakuhub/auth/email.py
+++ b/src/kohakuhub/auth/email.py
@@ -8,17 +8,27 @@ from ..config import cfg
def send_verification_email(to_email: str, username: str, token: str) -> bool:
- """Send email verification email."""
+ """Send email verification email.
+
+ Note: HTML emails have limitations:
+ - Must use inline CSS (no