Skip to content

Commit d608200

Browse files
fix(builder): stop google calendar oauth callback from swallowing its own redirect (#1037)
The success redirect() lived inside the try block, so Next's NEXT_REDIRECT throw was caught by the catch and reported as a connect failure even when the OAuth exchange and DB write both succeeded. Move the redirect outside try/catch and track the outcome via a connectStatus variable instead.
1 parent 49803d2 commit d608200

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

  • apps/builder/src/app/integrations/[...integration]

apps/builder/src/app/integrations/[...integration]/callback.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ export const handleCallback = async (
598598
googleCredential,
599599
"/integrations/google-calendar/callback",
600600
)
601+
let connectStatus: "success" | "error" = "success"
601602
try {
602603
const connection = await exchangeAndVerifyGoogleCalendar({
603604
credentialConfig: googleCredential.config,
@@ -612,21 +613,18 @@ export const handleCallback = async (
612613
providerCalendarId: connection.providerCalendarId,
613614
email: connection.email,
614615
})
615-
616-
const successUrl = new URL(safeReferer)
617-
successUrl.searchParams.set("externalCalendarConnect", "success")
618-
619-
return redirect(successUrl.toString())
620616
} catch (error) {
621617
logger.error(
622618
{ err: normalizeError(error), workspaceId: workspace.id },
623619
"Failed to connect Google Calendar from OAuth callback",
624620
)
625-
const errorUrl = new URL(safeReferer)
626-
errorUrl.searchParams.set("externalCalendarConnect", "error")
627-
628-
return redirect(errorUrl.toString())
621+
connectStatus = "error"
629622
}
623+
624+
const resultUrl = new URL(safeReferer)
625+
resultUrl.searchParams.set("externalCalendarConnect", connectStatus)
626+
627+
return redirect(resultUrl.toString())
630628
}
631629

632630
case "googleSheets": {

0 commit comments

Comments
 (0)