Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Wait for a signed-in user before fetching signing sessions (#8227)

Anthony Stirling9bc73495ccf6
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.toml
index b819c53735..af0b84e24b 100644
--- a/frontend/editor/public/locales/en-US/translation.toml
+++ b/frontend/editor/public/locales/en-US/translation.toml
@@ -12117,6 +12117,8 @@ filterSigned = "Signed"
fromOwner = "From {{owner}}"
newRequest = "Request signatures"
signedCount = "{{signed}}/{{total}} signed"
+signInRequiredBody = "Sign in to request signatures and see requests sent to you."
+signInRequiredTitle = "Sign in required"
[sharedSign.empty]
active = "No pending sign requests or active sessions"
diff --git a/frontend/editor/src/core/components/shared/quickNav/useQuickNavToolReasons.test.tsx b/frontend/editor/src/core/components/shared/quickNav/useQuickNavToolReasons.test.tsx
index 6295ddde66..945a67fc74 100644
--- a/frontend/editor/src/core/components/shared/quickNav/useQuickNavToolReasons.test.tsx
+++ b/frontend/editor/src/core/components/shared/quickNav/useQuickNavToolReasons.test.tsx
@@ -8,6 +8,7 @@ const h = vi.hoisted(() => ({
loading: false,
configLoading: false,
groupSigningEnabled: true,
+ isAnonymous: false,
}));
vi.mock("@app/hooks/useEndpointConfig", () => ({
@@ -33,6 +34,10 @@ vi.mock("@app/hooks/useGroupSigningEnabled", () => ({
useGroupSigningEnabled: () => h.groupSigningEnabled,
}));
+vi.mock("@app/auth/UseSession", () => ({
+ useAuth: () => ({ isAnonymous: h.isAnonymous }),
+}));
+
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (_key: string, fallback?: string) => fallback ?? _key,
@@ -47,6 +52,23 @@ describe("useQuickNavToolReasons", () => {
h.loading = false;
h.configLoading = false;
h.groupSigningEnabled = true;
+ h.isAnonymous = false;
+ });
+
+ it("asks a guest to sign in and does not remember that for the next user", () => {
+ h.groupSigningEnabled = false;
+ h.isAnonymous = true;
+
+ const { result } = renderHook(() => useQuickNavToolReasons());
+ expect(result.current?.sharedSign).toBe(
+ "Sign in to request signatures and see requests sent to you",
+ );
+
+ h.loading = true;
+ h.groupSigningEnabled = true;
+ h.isAnonymous = false;
+ const next = renderHook(() => useQuickNavToolReasons());
+ expect(next.result.current?.sharedSign).toBeUndefined();
});
it("admits it does not know rather than reporting nothing wrong", () => {
diff --git a/frontend/editor/src/core/components/shared/quickNav/useQuickNavToolReasons.ts b/frontend/editor/src/core/components/shared/quickNav/useQuickNavToolReasons.ts
index 235f4d4f08..989c2eea16 100644
--- a/frontend/editor/src/core/components/shared/quickNav/useQuickNavToolReasons.ts
+++ b/frontend/editor/src/core/components/shared/quickNav/useQuickNavToolReasons.ts
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import { useMultipleEndpointsEnabled } from "@app/hooks/useEndpointConfig";
import { useAppConfig } from "@app/contexts/AppConfigContext";
import { useGroupSigningEnabled } from "@app/hooks/useGroupSigningEnabled";
+import { useAuth } from "@app/auth/UseSession";
import { getDisabledLabel } from "@app/components/tools/fullscreen/shared";
import type { QuickNavToolReasons } from "@app/contexts/QuickNavHostContext";
import type { ToolId } from "@app/types/toolId";
@@ -18,7 +19,8 @@ const ENDPOINT_ENTRIES = Object.keys(
/** Shared signing is a feature toggle rather than an endpoint, so it has its own cause. */
type EndpointCause = "missingDependency" | "disabledByAdmin";
-type Cause = EndpointCause | "groupSigningOff";
+// Guest-only; left out of CAUSES so it is never read back for whoever signs in next.
+type Cause = EndpointCause | "groupSigningOff" | "signInRequired";
type Causes = Partial<Record<ToolId, Cause>>;
const CAUSES: Cause[] = [
"missingDependency",
@@ -85,12 +87,15 @@ export function useQuickNavToolReasons(): QuickNavToolReasons | null {
const { loading: configLoading } = useAppConfig();
const groupSigningEnabled = useGroupSigningEnabled();
+ const { isAnonymous } = useAuth();
const live = useMemo(() => {
// A half answer would dim entries it can't see yet.
if (loading || configLoading) return null;
const causes = causesFor(endpointStatus, endpointDetails);
- if (!groupSigningEnabled) causes.sharedSign = "groupSigningOff";
+ if (!groupSigningEnabled) {
+ causes.sharedSign = isAnonymous ? "signInRequired" : "groupSigningOff";
+ }
return causes;
}, [
loading,
@@ -98,6 +103,7 @@ export function useQuickNavToolReasons(): QuickNavToolReasons | null {
endpointStatus,
endpointDetails,
groupSigningEnabled,
+ isAnonymous,
]);
// Keyed on contents: the object is rebuilt every render.
@@ -113,6 +119,13 @@ export function useQuickNavToolReasons(): QuickNavToolReasons | null {
const reasons: QuickNavToolReasons = {};
for (const entry of Object.keys(causes) as ToolId[]) {
const cause = causes[entry];
+ if (cause === "signInRequired") {
+ reasons[entry] = t(
+ "sharedSign.signInRequiredBody",
+ "Sign in to request signatures and see requests sent to you.",
+ ).replace(/\.\s*$/, "");
+ continue;
+ }
if (cause === "groupSigningOff") {
// The tool's own wording, minus the full stop.
reasons[entry] = t(
diff --git a/frontend/editor/src/core/hooks/useGroupSigningEnabled.test.ts b/frontend/editor/src/core/hooks/useGroupSigningEnabled.test.ts
new file mode 100644
index 0000000000..5ae6af195d
--- /dev/null
+++ b/frontend/editor/src/core/hooks/useGroupSigningEnabled.test.ts
@@ -0,0 +1,29 @@
+import { describe, it, expect, vi, beforeEach } from "vitest";
+import { renderHook } from "@testing-library/react";
+import { useGroupSigningState } from "@app/hooks/useGroupSigningEnabled";
+
+vi.mock("@app/contexts/AppConfigContext", () => ({
+ useAppConfig: () => ({
+ config: { storageGroupSigningEnabled: true },
+ loading: false,
+ }),
+}));
+const authState = vi.hoisted(() => ({ isAnonymous: false }));
+vi.mock("@app/auth/UseSession", () => ({ useAuth: () => authState }));
+
+describe("useGroupSigningState", () => {
+ beforeEach(() => {
+ authState.isAnonymous = false;
+ });
+
+ it("follows the server config for an account", () => {
+ const { result } = renderHook(() => useGroupSigningState());
+ expect(result.current).toEqual({ enabled: true, settled: true });
+ });
+
+ it("is off for a guest", () => {
+ authState.isAnonymous = true;
+ const { result } = renderHook(() => useGroupSigningState());
+ expect(result.current).toEqual({ enabled: false, settled: true });
+ });
+});
diff --git a/frontend/editor/src/core/hooks/useGroupSigningEnabled.ts b/frontend/editor/src/core/hooks/useGroupSigningEnabled.ts
index 3871637c4d..de32251088 100644
--- a/frontend/editor/src/core/hooks/useGroupSigningEnabled.ts
+++ b/frontend/editor/src/core/hooks/useGroupSigningEnabled.ts
@@ -1,8 +1,9 @@
import { useAppConfig } from "@app/contexts/AppConfigContext";
+import { useAuth } from "@app/auth/UseSession";
/**
* Returns whether the shared (group) signing feature is available.
- * Core implementation reads directly from server config.
+ * Core implementation reads server config and turns it off for guests.
*/
export function useGroupSigningEnabled(): boolean {
return useGroupSigningState().enabled;
@@ -11,8 +12,10 @@ export function useGroupSigningEnabled(): boolean {
/** Unsettled availability must not replace a previously resolved signing badge. */
export function useGroupSigningState(): { enabled: boolean; settled: boolean } {
const { config, loading } = useAppConfig();
+ // Guests cannot be invited or invite anyone, and the signing endpoints reject them.
+ const { isAnonymous } = useAuth();
return {
- enabled: config?.storageGroupSigningEnabled === true,
+ enabled: !isAnonymous && config?.storageGroupSigningEnabled === true,
settled: !loading,
};
}
diff --git a/frontend/editor/src/core/tools/SharedSign.tsx b/frontend/editor/src/core/tools/SharedSign.tsx
index 70e9961975..f6cfd5812b 100644
--- a/frontend/editor/src/core/tools/SharedSign.tsx
+++ b/frontend/editor/src/core/tools/SharedSign.tsx
@@ -16,6 +16,7 @@ import { useTranslation } from "react-i18next";
import { Icon } from "@app/ui/Icon";
import type { BaseToolProps } from "@app/types/tool";
import { useGroupSigningEnabled } from "@app/hooks/useGroupSigningEnabled";
+import { useAuth } from "@app/auth/UseSession";
import { useViewScopedFiles } from "@app/hooks/tools/shared/useViewScopedFiles";
import { useSigningSessionController } from "@app/hooks/signing/useSigningSessionController";
import { CreateSessionFlow } from "@app/components/shared/signing/CreateSessionFlow";
@@ -41,6 +42,7 @@ function sortByRecency(items: SessionItem[]): SessionItem[] {
const SharedSign = (_props: BaseToolProps) => {
const { t } = useTranslation();
const groupSigningEnabled = useGroupSigningEnabled();
+ const { isAnonymous } = useAuth();
const controller = useSigningSessionController(groupSigningEnabled);
const selectedFiles = useViewScopedFiles();
@@ -134,6 +136,22 @@ const SharedSign = (_props: BaseToolProps) => {
}
};
+ if (!groupSigningEnabled && isAnonymous) {
+ return (
+ <Stack p="md">
+ <Alert
+ color="yellow"
+ title={t("sharedSign.signInRequiredTitle", "Sign in required")}
+ >
+ {t(
+ "sharedSign.signInRequiredBody",
+ "Sign in to request signatures and see requests sent to you.",
+ )}
+ </Alert>
+ </Stack>
+ );
+ }
+
if (!groupSigningEnabled) {
return (
<Stack p="md">