Skip to content

Commit aaa4672

Browse files
makerjackieclaude
andcommitted
revert: 回退 getInternalOrigin 改动,修复微信登录后无法跳转的问题
4dd36a9 将 middleware 内部 fetch 改为 http://localhost,导致请求 缺少 Host/x-forwarded-for 头,rate limiter 和 Better Auth 无法 正确识别客户端,session 检查始终失败。回退为直接使用 req.nextUrl.origin,在 Zeabur 部署环境下无 SSL 问题。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fac19e4 commit aaa4672

1 file changed

Lines changed: 5 additions & 19 deletions

File tree

packages/lib-shared/src/middleware-helpers.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,12 @@ export interface Organization {
1111
[key: string]: unknown;
1212
}
1313

14-
/**
15-
* Get the internal origin for middleware self-referencing fetch calls.
16-
* In Docker/production behind a reverse proxy, req.nextUrl.origin is the
17-
* external HTTPS URL, but the container only serves HTTP. Using localhost
18-
* avoids SSL issues and is more efficient (no network round trip).
19-
*/
20-
function getInternalOrigin(requestOrigin: string): string {
21-
// On Vercel, edge middleware can use the request origin directly
22-
if (process.env.NEXT_PUBLIC_VERCEL_URL) {
23-
return requestOrigin;
24-
}
25-
// In Docker/self-hosted environments, use localhost to avoid SSL issues
26-
return `http://localhost:${process.env.PORT ?? 3000}`;
27-
}
28-
2914
export const getSession = async (req: NextRequest): Promise<Session | null> => {
30-
const origin = getInternalOrigin(req.nextUrl.origin);
3115
const response = await fetch(
32-
new URL("/api/auth/get-session?disableCookieCache=true", origin),
16+
new URL(
17+
"/api/auth/get-session?disableCookieCache=true",
18+
req.nextUrl.origin,
19+
),
3320
{
3421
headers: {
3522
cookie: req.headers.get("cookie") || "",
@@ -53,9 +40,8 @@ export const getSession = async (req: NextRequest): Promise<Session | null> => {
5340
export const getOrganizationsForSession = async (
5441
req: NextRequest,
5542
): Promise<Organization[]> => {
56-
const origin = getInternalOrigin(req.nextUrl.origin);
5743
const response = await fetch(
58-
new URL("/api/auth/organization/list", origin),
44+
new URL("/api/auth/organization/list", req.nextUrl.origin),
5945
{
6046
headers: {
6147
cookie: req.headers.get("cookie") || "",

0 commit comments

Comments
 (0)