Skip to content

Commit c7ee679

Browse files
committed
fix (settings): google apps redirect issue
1 parent 61d20bd commit c7ee679

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • src/client/app/api/settings/integrations/connect/oauth/callback

src/client/app/api/settings/integrations/connect/oauth/callback/route.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)