diff --git a/app/scenes/Document/Shared.tsx b/app/scenes/Document/Shared.tsx index 7f0adb5829..6e9e113c23 100644 --- a/app/scenes/Document/Shared.tsx +++ b/app/scenes/Document/Shared.tsx @@ -25,6 +25,7 @@ import useBuildTheme from "~/hooks/useBuildTheme"; import useCurrentUser from "~/hooks/useCurrentUser"; import { usePostLoginPath } from "~/hooks/useLastVisitedPath"; import useStores from "~/hooks/useStores"; +import { client } from "~/utils/ApiClient"; import { AuthorizationError, OfflineError } from "~/utils/errors"; import isCloudHosted from "~/utils/isCloudHosted"; import { changeLanguage, detectLanguage } from "~/utils/language"; @@ -109,6 +110,16 @@ function SharedDocumentScene(props: Props) { : undefined; const theme = useBuildTheme(response?.team?.customTheme, themeOverride); + React.useEffect(() => { + if (shareId) { + client.setShareId(shareId); + } + + return () => { + client.setShareId(undefined); + }; + }, [shareId]); + React.useEffect(() => { if (!user) { void changeLanguage(detectLanguage(), i18n); diff --git a/app/utils/ApiClient.ts b/app/utils/ApiClient.ts index 7d5f295213..f1132b7213 100644 --- a/app/utils/ApiClient.ts +++ b/app/utils/ApiClient.ts @@ -36,10 +36,16 @@ const fetchWithRetry = retry(fetch); class ApiClient { baseUrl: string; + shareId?: string; + constructor(options: Options = {}) { this.baseUrl = options.baseUrl || "/api"; } + setShareId = (shareId: string | undefined) => { + this.shareId = shareId; + }; + fetch = async ( path: string, method: string, @@ -51,6 +57,14 @@ class ApiClient { let urlToFetch; let isJson; + if (this.shareId) { + // add to data + data = { + ...(data || {}), + shareId: this.shareId, + }; + } + if (method === "GET") { if (data) { modifiedPath = `${path}?${data && queryString.stringify(data)}`;