Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: Safari onboarding + general redirection (#920)

Ameer Al Ashhab7950b313e25b
diff --git a/apps/web/app/(org)/onboarding/Onboarding.tsx b/apps/web/app/(org)/onboarding/Onboarding.tsx
index 2c2fc11c2..6e5a53051 100644
--- a/apps/web/app/(org)/onboarding/Onboarding.tsx
+++ b/apps/web/app/(org)/onboarding/Onboarding.tsx
@@ -1,6 +1,7 @@
"use client";
import { Button, Input } from "@cap/ui";
+import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { UpgradeModal } from "@/components/UpgradeModal";
@@ -10,6 +11,8 @@ export const Onboarding = () => {
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [showUpgradeModal, setShowUpgradeModal] = useState(false);
+ const router = useRouter();
+ const [isRedirecting, setIsRedirecting] = useState(false);
const onboardingRequest = async () => {
const response = await fetch("/api/settings/onboarding", {
@@ -36,8 +39,8 @@ export const Onboarding = () => {
if (!response.isMemberOfOrganization) {
setShowUpgradeModal(true);
} else {
- // Force complete page reload to bypass React cache
- window.location.replace("/dashboard");
+ router.refresh();
+ setIsRedirecting(true);
}
} catch {
toast.error("Failed to complete onboarding");
@@ -61,6 +64,7 @@ export const Onboarding = () => {
name="firstName"
required
value={firstName}
+ disabled={loading || isRedirecting}
onChange={(e) => setFirstName(e.target.value)}
/>
</div>
@@ -72,17 +76,22 @@ export const Onboarding = () => {
placeholder="Last name"
required
value={lastName}
+ disabled={loading || isRedirecting}
onChange={(e) => setLastName(e.target.value)}
/>
</div>
</div>
<Button
- disabled={!firstName || !lastName || loading}
+ disabled={!firstName || !lastName || loading || isRedirecting}
className="mx-auto mt-6 w-full"
type="submit"
- spinner={loading}
+ spinner={loading || isRedirecting}
>
- {loading ? "Submitting..." : "Submit"}
+ {isRedirecting
+ ? "Redirecting..."
+ : loading
+ ? "Submitting..."
+ : "Submit"}
</Button>
</form>
@@ -91,7 +100,8 @@ export const Onboarding = () => {
onOpenChange={(open) => {
setShowUpgradeModal(open);
if (!open) {
- window.location.replace("/dashboard");
+ router.refresh();
+ setIsRedirecting(true);
}
}}
/>
diff --git a/apps/web/app/(org)/verify-otp/form.tsx b/apps/web/app/(org)/verify-otp/form.tsx
index 22812aab0..6bce9e63b 100644
--- a/apps/web/app/(org)/verify-otp/form.tsx
+++ b/apps/web/app/(org)/verify-otp/form.tsx
@@ -87,6 +87,7 @@ export function VerifyOTPForm({
}
},
onSuccess: () => {
+ router.refresh();
router.replace(next || "/dashboard");
},
onError: (e) => {
diff --git a/apps/web/app/api/settings/onboarding/route.ts b/apps/web/app/api/settings/onboarding/route.ts
index 192d412bc..3f9255021 100644
--- a/apps/web/app/api/settings/onboarding/route.ts
+++ b/apps/web/app/api/settings/onboarding/route.ts
@@ -92,7 +92,6 @@ export async function POST(request: NextRequest) {
}
revalidatePath("/onboarding");
- revalidatePath("/dashboard");
return Response.json(
{
diff --git a/packages/database/auth/auth-options.tsx b/packages/database/auth/auth-options.tsx
index 85e0961b2..3be56d58f 100644
--- a/packages/database/auth/auth-options.tsx
+++ b/packages/database/auth/auth-options.tsx
@@ -115,9 +115,9 @@ export const authOptions = (): NextAuthOptions => {
name: `next-auth.session-token`,
options: {
httpOnly: true,
- sameSite: "none",
+ sameSite: "lax",
path: "/",
- secure: true,
+ secure: process.env.NODE_ENV === "production",
},
},
},