@@ -8,7 +8,15 @@ export async function GET(request) {
88 const state = searchParams . get ( "state" ) // This will be 'gdrive', 'gcalendar', etc.
99 const error = searchParams . get ( "error" )
1010
11- const settingsUrl = new URL ( "/settings" , request . url )
11+ const baseUrl = process . env . APP_BASE_URL
12+ if ( ! baseUrl ) {
13+ console . error ( "APP_BASE_URL environment variable is not set." )
14+ return new Response ( "Server configuration error." , { status : 500 } )
15+ }
16+
17+ // FIX: Use the public-facing APP_BASE_URL for redirection, not the internal request.url.
18+ // This ensures the browser is redirected to the correct, publicly accessible address.
19+ const settingsUrl = new URL ( "/settings" , baseUrl )
1220
1321 if ( error ) {
1422 // User denied access or an error occurred
@@ -33,7 +41,7 @@ export async function GET(request) {
3341 // The browser session (cookie) is automatically forwarded by Next.js server-side fetch,
3442 // which authenticates the user to our own API proxy.
3543 const apiResponse = await fetch (
36- `${ process . env . APP_BASE_URL } /api/settings/integrations/connect/oauth` ,
44+ `${ baseUrl } /api/settings/integrations/connect/oauth` ,
3745 {
3846 method : "POST" ,
3947 headers : {
@@ -43,7 +51,7 @@ export async function GET(request) {
4351 body : JSON . stringify ( {
4452 service_name : state ,
4553 code : code ,
46- redirect_uri : `${ process . env . APP_BASE_URL } /api/settings/integrations/connect/oauth/callback`
54+ redirect_uri : `${ baseUrl } /api/settings/integrations/connect/oauth/callback`
4755 } )
4856 }
4957 )
0 commit comments