mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
use return_url to redirect back after google drive reauth
This commit is contained in:
parent
afbf448f88
commit
24aa7c51a4
3 changed files with 8 additions and 10 deletions
|
|
@ -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}"
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue