@@ -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-
2914export 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> => {
5340export 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