Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: show the not-found page for deleted shared videos and offer an Apple sign-in retry

Richie McIlroy9bd0f7b59d1b
diff --git a/apps/web/__tests__/unit/oauth-sign-in-errors.test.ts b/apps/web/__tests__/unit/oauth-sign-in-errors.test.ts
index 6b79281c8..67f92ade1 100644
--- a/apps/web/__tests__/unit/oauth-sign-in-errors.test.ts
+++ b/apps/web/__tests__/unit/oauth-sign-in-errors.test.ts
@@ -132,15 +132,30 @@ describe.each([
});
});
-it.each(["apple", "google"])(
- "handles failed automatic mobile %s sign-in without an unhandled rejection",
- async (provider) => {
- mocks.searchParams.set("mobileProvider", provider);
- mocks.signIn.mockRejectedValueOnce(new TypeError("Load failed"));
- await act(async () => root.render(createElement(LoginForm)));
- expect(mocks.signIn).toHaveBeenCalledWith(provider, {});
- expect(mocks.error).toHaveBeenCalledWith(
- "Could not start sign-in. Check your connection and try again.",
- );
- },
-);
+it("handles failed automatic mobile google sign-in without an unhandled rejection", async () => {
+ mocks.searchParams.set("mobileProvider", "google");
+ mocks.signIn.mockRejectedValueOnce(new TypeError("Load failed"));
+ await act(async () => root.render(createElement(LoginForm)));
+ expect(mocks.signIn).toHaveBeenCalledWith("google", {});
+ expect(mocks.error).toHaveBeenCalledWith(
+ "Could not start sign-in. Check your connection and try again.",
+ );
+});
+
+it("offers a retry after failed automatic mobile apple sign-in", async () => {
+ mocks.searchParams.set("mobileProvider", "apple");
+ mocks.signIn.mockRejectedValueOnce(new TypeError("Load failed"));
+ await act(async () => root.render(createElement(LoginForm)));
+ expect(mocks.signIn).toHaveBeenCalledWith("apple", {});
+ expect(mocks.error).toHaveBeenLastCalledWith(
+ "Could not start sign-in. Check your connection and try again.",
+ { action: { label: "Try again", onClick: expect.any(Function) } },
+ );
+
+ const options = mocks.error.mock.lastCall?.[1] as
+ | { action: { onClick: () => void } }
+ | undefined;
+ await act(async () => options?.action.onClick());
+ expect(mocks.signIn).toHaveBeenCalledTimes(2);
+ expect(mocks.signIn).toHaveBeenLastCalledWith("apple", {});
+});
diff --git a/apps/web/app/(org)/login/form.tsx b/apps/web/app/(org)/login/form.tsx
index 4cf4ec942..e7f9af333 100644
--- a/apps/web/app/(org)/login/form.tsx
+++ b/apps/web/app/(org)/login/form.tsx
@@ -174,22 +174,26 @@ export function LoginForm() {
}, [getNextPath]);
const handleAppleSignIn = useCallback(() => {
- const nextPath = getNextPath();
- trackEvent("auth_started", {
- method: "apple",
- is_signup: false,
- auth_surface: "login",
- });
- signIn("apple", {
- ...(nextPath ? { callbackUrl: nextPath } : {}),
- }).catch((error) => {
- captureException(error, {
- tags: { auth_provider: "apple", auth_surface: "login" },
+ const startAppleSignIn = () => {
+ const nextPath = getNextPath();
+ trackEvent("auth_started", {
+ method: "apple",
+ is_signup: false,
+ auth_surface: "login",
});
- toast.error(
- "Could not start sign-in. Check your connection and try again.",
- );
- });
+ signIn("apple", {
+ ...(nextPath ? { callbackUrl: nextPath } : {}),
+ }).catch((error) => {
+ captureException(error, {
+ tags: { auth_provider: "apple", auth_surface: "login" },
+ });
+ toast.error(
+ "Could not start sign-in. Check your connection and try again.",
+ { action: { label: "Try again", onClick: startAppleSignIn } },
+ );
+ });
+ };
+ startAppleSignIn();
}, [getNextPath]);
const handleOidcSignIn = useCallback(() => {
diff --git a/apps/web/app/s/[videoId]/Share.tsx b/apps/web/app/s/[videoId]/Share.tsx
index 63a24c504..73e15f178 100644
--- a/apps/web/app/s/[videoId]/Share.tsx
+++ b/apps/web/app/s/[videoId]/Share.tsx
@@ -8,7 +8,7 @@ import clsx from "clsx";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import dynamic from "next/dynamic";
import Image from "next/image";
-import { useSearchParams } from "next/navigation";
+import { useRouter, useSearchParams } from "next/navigation";
import {
Suspense,
startTransition,
@@ -360,7 +360,7 @@ export const Share = ({
},
);
- const { data: videoStatus } = useVideoStatus(
+ const { data: videoStatus, error: videoStatusError } = useVideoStatus(
data.id,
{
aiGeneration: aiGenerationAvailable,
@@ -373,6 +373,11 @@ export const Share = ({
},
!isScreenshot,
);
+ const router = useRouter();
+ const videoWasDeleted = videoStatusError instanceof VideoStatusNotFoundError;
+ useEffect(() => {
+ if (videoWasDeleted) router.refresh();
+ }, [videoWasDeleted, router]);
const transcriptionStatus =
videoStatus?.transcriptionStatus || data.transcriptionStatus;