diff --git a/surfsense_backend/app/routes/google_drive_add_connector_route.py b/surfsense_backend/app/routes/google_drive_add_connector_route.py index 5cab5b02b..9fa83f3a2 100644 --- a/surfsense_backend/app/routes/google_drive_add_connector_route.py +++ b/surfsense_backend/app/routes/google_drive_add_connector_route.py @@ -155,7 +155,7 @@ async def connect_drive(space_id: int, user: User = Depends(current_active_user) async def reauth_drive( space_id: int, connector_id: int, - thread_id: str | None = None, + return_url: str | None = None, user: User = Depends(current_active_user), session: AsyncSession = Depends(get_async_session), ): @@ -195,8 +195,8 @@ async def reauth_drive( state_manager = get_state_manager() extra: dict = {"connector_id": connector_id} - if thread_id: - extra["thread_id"] = thread_id + if return_url and return_url.startswith("/"): + extra["return_url"] = return_url state_encoded = state_manager.generate_secure_state(space_id, user.id, **extra) auth_url, _ = flow.authorization_url( @@ -284,7 +284,7 @@ async def drive_callback( user_id = UUID(data["user_id"]) space_id = data["space_id"] reauth_connector_id = data.get("connector_id") - reauth_thread_id = data.get("thread_id") + reauth_return_url = data.get("return_url") logger.info( f"Processing Google Drive callback for user {user_id}, space {space_id}" @@ -355,9 +355,9 @@ async def drive_callback( logger.info( f"Re-authenticated Google Drive connector {db_connector.id} for user {user_id}" ) - if reauth_thread_id: + if reauth_return_url and reauth_return_url.startswith("/"): return RedirectResponse( - url=f"{config.NEXT_FRONTEND_URL}/dashboard/{space_id}/new-chat/{reauth_thread_id}" + url=f"{config.NEXT_FRONTEND_URL}{reauth_return_url}" ) return RedirectResponse( url=f"{config.NEXT_FRONTEND_URL}/dashboard/{space_id}/new-chat?modal=connectors&tab=all&success=true&connector=google-drive-connector&connectorId={db_connector.id}" diff --git a/surfsense_web/components/tool-ui/google-drive/create-file.tsx b/surfsense_web/components/tool-ui/google-drive/create-file.tsx index 160021191..548347587 100644 --- a/surfsense_web/components/tool-ui/google-drive/create-file.tsx +++ b/surfsense_web/components/tool-ui/google-drive/create-file.tsx @@ -415,7 +415,6 @@ function ApprovalCard({ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissionsResult }) { const params = useParams(); const searchSpaceId = params.search_space_id as string; - const threadId = (params.chat_id as string[] | undefined)?.[0]; const [loading, setLoading] = useState(false); async function handleReauth() { @@ -425,7 +424,7 @@ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissio const url = new URL(`${backendUrl}/api/v1/auth/google/drive/connector/reauth`); url.searchParams.set("connector_id", String(result.connector_id)); url.searchParams.set("space_id", searchSpaceId); - if (threadId) url.searchParams.set("thread_id", threadId); + url.searchParams.set("return_url", window.location.pathname); const response = await authenticatedFetch(url.toString()); const data = await response.json(); if (data.auth_url) { diff --git a/surfsense_web/components/tool-ui/google-drive/trash-file.tsx b/surfsense_web/components/tool-ui/google-drive/trash-file.tsx index 2053356a4..29bf7df16 100644 --- a/surfsense_web/components/tool-ui/google-drive/trash-file.tsx +++ b/surfsense_web/components/tool-ui/google-drive/trash-file.tsx @@ -281,7 +281,6 @@ function ApprovalCard({ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissionsResult }) { const params = useParams(); const searchSpaceId = params.search_space_id as string; - const threadId = (params.chat_id as string[] | undefined)?.[0]; const [loading, setLoading] = useState(false); async function handleReauth() { @@ -291,7 +290,7 @@ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissio const url = new URL(`${backendUrl}/api/v1/auth/google/drive/connector/reauth`); url.searchParams.set("connector_id", String(result.connector_id)); url.searchParams.set("space_id", searchSpaceId); - if (threadId) url.searchParams.set("thread_id", threadId); + url.searchParams.set("return_url", window.location.pathname); const response = await authenticatedFetch(url.toString()); const data = await response.json(); if (data.auth_url) {