diff --git a/apps/web/app/(org)/onboarding/Onboarding.tsx b/apps/web/app/(org)/onboarding/Onboarding.tsx index 2c2fc11c2f..6e5a530510 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)} /> @@ -72,17 +76,22 @@ export const Onboarding = () => { placeholder="Last name" required value={lastName} + disabled={loading || isRedirecting} onChange={(e) => setLastName(e.target.value)} /> @@ -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 22812aab0f..6bce9e63b5 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 192d412bc3..3f9255021d 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 85e0961b2a..3be56d58f2 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", }, }, },