Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Preserve `next` query param in partner onboarding flow (#3505)

Steven Tey501012ae2a61
diff --git a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx
index 287478a769..5def5cd422 100644
--- a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx
@@ -3,6 +3,7 @@
import { parseActionError } from "@/lib/actions/parse-action-errors";
import { PartnerData } from "@/lib/actions/partners/create-program-application";
import { onboardPartnerAction } from "@/lib/actions/partners/onboard-partner";
+import { getValidInternalRedirectPath } from "@/lib/middleware/utils/is-valid-internal-redirect";
import { onboardPartnerSchema } from "@/lib/zod/schemas/partners";
import { CountryCombobox } from "@/ui/partners/country-combobox";
import { Partner } from "@dub/prisma/client";
@@ -19,7 +20,7 @@ import { cn } from "@dub/utils";
import { AnimatePresence, LayoutGroup, motion } from "motion/react";
import { useSession } from "next-auth/react";
import { useAction } from "next-safe-action/hooks";
-import { useRouter } from "next/navigation";
+import { useRouter, useSearchParams } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import ReactTextareaAutosize from "react-textarea-autosize";
@@ -45,6 +46,7 @@ export function OnboardingForm({
> | null;
}) {
const router = useRouter();
+ const searchParams = useSearchParams();
const { isMobile } = useMediaQuery();
const [accountCreated, setAccountCreated] = useState(false);
const { data: session, update: refreshSession } = useSession();
@@ -93,7 +95,13 @@ export function OnboardingForm({
const { executeAsync, isPending } = useAction(onboardPartnerAction, {
onSuccess: () => {
setAccountCreated(true);
- router.push("/onboarding/platforms");
+ const next = getValidInternalRedirectPath({
+ redirectPath: searchParams.get("next"),
+ currentUrl: window.location.href,
+ });
+ router.push(
+ `/onboarding/platforms${next ? `?next=${encodeURIComponent(next)}` : ""}`,
+ );
},
onError: ({ error, input }) => {
toast.error(parseActionError(error, "An unknown error occurred."));
diff --git a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/payouts/page.tsx b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/payouts/page.tsx
index ad2b9ba8cb..b14305bd38 100644
--- a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/payouts/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/payouts/page.tsx
@@ -1,13 +1,12 @@
import { getSession } from "@/lib/auth";
-import { ConnectPayoutButton } from "@/ui/partners/connect-payout-button";
import { prisma } from "@dub/prisma";
import {
CONNECT_SUPPORTED_COUNTRIES,
PAYPAL_SUPPORTED_COUNTRIES,
} from "@dub/utils";
-import Link from "next/link";
import { redirect } from "next/navigation";
import { Suspense } from "react";
+import { PayoutProvider } from "./payout-provider";
export default function OnboardingVerificationPage() {
return (
@@ -24,63 +23,6 @@ export default function OnboardingVerificationPage() {
);
}
-function PayoutProvider({ provider }: { provider: "stripe" | "paypal" }) {
- const providers = {
- stripe: {
- label: "Stripe",
- logo: "https://assets.dub.co/misc/stripe-wordmark.svg",
- },
- paypal: {
- label: "Paypal",
- logo: "https://assets.dub.co/misc/paypal-wordmark.svg",
- },
- }[provider];
-
- const { label, logo } = providers;
-
- return (
- <>
- <div className="divide-y divide-neutral-200 overflow-hidden rounded-lg border border-neutral-200">
- <div className="flex items-center justify-center bg-neutral-50 p-4">
- <img
- src={logo}
- alt={`${label} wordmark`}
- className="aspect-[96/40] h-10"
- />
- </div>
- <div className="bg-white px-6 py-4 text-sm text-neutral-600">
- We use {label} to ensure you get paid on time and to keep your
- personal bank details secure. Click <strong>Connect payouts</strong>{" "}
- to connect your bank account.
- <br />
- <br />
- You can complete this at a later date, but won't be able to collect
- any payouts until it's completed.
- <br />
- <br />
- <a
- href="https://dub.co/help/article/receiving-payouts"
- target="_blank"
- className="cursor-help text-sm text-neutral-500 underline decoration-dotted underline-offset-2 transition-colors hover:text-neutral-800"
- >
- Learn more about receiving payouts on Dub.
- </a>
- </div>
- </div>
- <div className="mt-10 grid gap-4">
- <ConnectPayoutButton text="Connect payouts" />
-
- <Link
- href="/programs"
- className="text-sm font-medium text-neutral-800 transition-colors hover:text-neutral-950"
- >
- I'll complete this later
- </Link>
- </div>
- </>
- );
-}
-
function PayoutSkeleton() {
return (
<>
diff --git a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/payouts/payout-provider.tsx b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/payouts/payout-provider.tsx
new file mode 100644
index 0000000000..408d21f789
--- /dev/null
+++ b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/payouts/payout-provider.tsx
@@ -0,0 +1,73 @@
+"use client";
+
+import { getValidInternalRedirectPath } from "@/lib/middleware/utils/is-valid-internal-redirect";
+import { ConnectPayoutButton } from "@/ui/partners/connect-payout-button";
+import Link from "next/link";
+import { useSearchParams } from "next/navigation";
+
+export function PayoutProvider({
+ provider,
+}: {
+ provider: "stripe" | "paypal";
+}) {
+ const searchParams = useSearchParams();
+ const next = getValidInternalRedirectPath({
+ redirectPath: searchParams.get("next"),
+ currentUrl: window.location.href,
+ });
+
+ const providers = {
+ stripe: {
+ label: "Stripe",
+ logo: "https://assets.dub.co/misc/stripe-wordmark.svg",
+ },
+ paypal: {
+ label: "Paypal",
+ logo: "https://assets.dub.co/misc/paypal-wordmark.svg",
+ },
+ }[provider];
+
+ const { label, logo } = providers;
+
+ return (
+ <>
+ <div className="divide-y divide-neutral-200 overflow-hidden rounded-lg border border-neutral-200">
+ <div className="flex items-center justify-center bg-neutral-50 p-4">
+ <img
+ src={logo}
+ alt={`${label} wordmark`}
+ className="aspect-[96/40] h-10"
+ />
+ </div>
+ <div className="bg-white px-6 py-4 text-sm text-neutral-600">
+ We use {label} to ensure you get paid on time and to keep your
+ personal bank details secure. Click <strong>Connect payouts</strong>{" "}
+ to connect your bank account.
+ <br />
+ <br />
+ You can complete this at a later date, but won't be able to collect
+ any payouts until it's completed.
+ <br />
+ <br />
+ <a
+ href="https://dub.co/help/article/receiving-payouts"
+ target="_blank"
+ className="cursor-help text-sm text-neutral-500 underline decoration-dotted underline-offset-2 transition-colors hover:text-neutral-800"
+ >
+ Learn more about receiving payouts on Dub.
+ </a>
+ </div>
+ </div>
+ <div className="mt-10 grid gap-4">
+ <ConnectPayoutButton text="Connect payouts" />
+
+ <Link
+ href={next ?? "/programs"}
+ className="text-sm font-medium text-neutral-800 transition-colors hover:text-neutral-950"
+ >
+ I'll complete this later
+ </Link>
+ </div>
+ </>
+ );
+}
diff --git a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/platforms/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/platforms/page-client.tsx
index bd97ecef64..02922827b6 100644
--- a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/platforms/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/platforms/page-client.tsx
@@ -1,9 +1,10 @@
"use client";
+import { getValidInternalRedirectPath } from "@/lib/middleware/utils/is-valid-internal-redirect";
import { PartnerProps } from "@/lib/types";
import { PartnerPlatformsForm } from "@/ui/partners/partner-platforms-form";
import Link from "next/link";
-import { useRouter } from "next/navigation";
+import { useRouter, useSearchParams } from "next/navigation";
export function OnboardingPlatformsPageClient({
partner,
@@ -11,16 +12,25 @@ export function OnboardingPlatformsPageClient({
partner: Pick<PartnerProps, "country" | "platforms">;
}) {
const router = useRouter();
+ const searchParams = useSearchParams();
+ const next = getValidInternalRedirectPath({
+ redirectPath: searchParams.get("next"),
+ currentUrl: window.location.href,
+ });
return (
<>
<PartnerPlatformsForm
- onSubmitSuccessful={() => router.push("/onboarding/payouts")}
+ onSubmitSuccessful={() =>
+ router.push(
+ `/onboarding/payouts${next ? `?next=${encodeURIComponent(next)}` : ""}`,
+ )
+ }
partner={partner}
variant="onboarding"
/>
<Link
- href="/onboarding/payouts"
+ href={`/onboarding/payouts${next ? `?next=${encodeURIComponent(next)}` : ""}`}
className="text-sm font-medium text-neutral-800 transition-colors hover:text-neutral-950"
>
I'll complete this later
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
index a325682be7..8dff299c03 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
@@ -41,7 +41,13 @@ import {
timeAgo,
} from "@dub/utils";
import Linkify from "linkify-react";
-import { Dispatch, SetStateAction, useCallback, useMemo, useState } from "react";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
import { toast } from "sonner";
type BountySubmissionDetailsSheetProps = {
@@ -58,7 +64,7 @@ function BountySubmissionDetailsSheetContent({
setIsOpen,
}: BountySubmissionDetailsSheetProps) {
const { bounty } = useBounty();
- const { id: workspaceId, slug: workspaceSlug } = useWorkspace();
+ const { slug: workspaceSlug } = useWorkspace();
const { setShowRejectModal, RejectBountySubmissionModal } =
useRejectBountySubmissionModal(submission, onNext);
@@ -529,9 +535,7 @@ function BountySubmissionDetailsSheetContent({
? "Bounty submission already rejected."
: undefined
}
- disabled={
- submission.status === "draft"
- }
+ disabled={submission.status === "draft"}
onClick={() => setShowRejectModal(true)}
/>
diff --git a/apps/web/lib/middleware/partners.ts b/apps/web/lib/middleware/partners.ts
index 85b967ea88..91c5e5badd 100644
--- a/apps/web/lib/middleware/partners.ts
+++ b/apps/web/lib/middleware/partners.ts
@@ -65,13 +65,23 @@ export async function PartnersMiddleware(req: NextRequest) {
!isPartnerInvite &&
!["/onboarding", "/account"].some((p) => path.startsWith(p))
) {
- return NextResponse.redirect(new URL("/onboarding", req.url));
+ return NextResponse.redirect(
+ new URL(
+ `/onboarding${path === "/" ? "" : `?next=${encodeURIComponent(fullPath)}`}`,
+ req.url,
+ ),
+ );
}
// Handle ?next= query param with proper validation to prevent open redirects
+ // (omit /onboarding from the check to make sure onboarding is completed)
if (
searchParamsObj.next &&
- isValidInternalRedirect(searchParamsObj.next, req.url)
+ isValidInternalRedirect({
+ redirectPath: searchParamsObj.next,
+ currentUrl: req.url,
+ }) &&
+ !path.startsWith("/onboarding")
) {
return NextResponse.redirect(new URL(searchParamsObj.next, req.url));
}
diff --git a/apps/web/lib/middleware/utils/is-valid-internal-redirect.ts b/apps/web/lib/middleware/utils/is-valid-internal-redirect.ts
index ef7d860f58..2b6adcbfbb 100644
--- a/apps/web/lib/middleware/utils/is-valid-internal-redirect.ts
+++ b/apps/web/lib/middleware/utils/is-valid-internal-redirect.ts
@@ -1,10 +1,13 @@
/**
* Validates if a redirect URL is safe for internal redirects
*/
-export function isValidInternalRedirect(
- redirectPath: string,
- currentUrl: string | URL,
-): boolean {
+export function isValidInternalRedirect({
+ redirectPath,
+ currentUrl,
+}: {
+ redirectPath: string;
+ currentUrl: string | URL;
+}): boolean {
try {
// Ensure the URL construction results in same-origin redirect
const redirectUrl = new URL(redirectPath, currentUrl);
@@ -16,3 +19,17 @@ export function isValidInternalRedirect(
return false;
}
}
+
+export function getValidInternalRedirectPath({
+ redirectPath,
+ currentUrl,
+}: {
+ redirectPath?: string | null;
+ currentUrl: string | URL;
+}): string | null {
+ if (!redirectPath) {
+ return null;
+ }
+ const valid = isValidInternalRedirect({ redirectPath, currentUrl });
+ return valid ? redirectPath : null;
+}
diff --git a/apps/web/lib/middleware/workspaces.ts b/apps/web/lib/middleware/workspaces.ts
index 6451475fd9..0e45f47cdc 100644
--- a/apps/web/lib/middleware/workspaces.ts
+++ b/apps/web/lib/middleware/workspaces.ts
@@ -13,7 +13,10 @@ export async function WorkspacesMiddleware(req: NextRequest, user: UserProps) {
// Handle ?next= query param with proper validation to prevent open redirects
if (
searchParamsObj.next &&
- isValidInternalRedirect(searchParamsObj.next, req.url)
+ isValidInternalRedirect({
+ redirectPath: searchParamsObj.next,
+ currentUrl: req.url,
+ })
) {
return NextResponse.redirect(new URL(searchParamsObj.next, req.url));
}
diff --git a/apps/web/ui/auth/register/signup-oauth.tsx b/apps/web/ui/auth/register/signup-oauth.tsx
index 727c3b5f6a..c1e6a0092a 100644
--- a/apps/web/ui/auth/register/signup-oauth.tsx
+++ b/apps/web/ui/auth/register/signup-oauth.tsx
@@ -1,5 +1,6 @@
"use client";
+import { getValidInternalRedirectPath } from "@/lib/middleware/utils/is-valid-internal-redirect";
import { Button, Github, Google } from "@dub/ui";
import { signIn } from "next-auth/react";
import { useSearchParams } from "next/navigation";
@@ -11,7 +12,10 @@ export const SignUpOAuth = ({
methods: ("email" | "google" | "github")[];
}) => {
const searchParams = useSearchParams();
- const next = searchParams?.get("next");
+ const next = getValidInternalRedirectPath({
+ redirectPath: searchParams.get("next"),
+ currentUrl: window.location.href,
+ });
const [clickedGoogle, setClickedGoogle] = useState(false);
const [clickedGithub, setClickedGithub] = useState(false);
diff --git a/apps/web/ui/auth/register/verify-email-form.tsx b/apps/web/ui/auth/register/verify-email-form.tsx
index ef6c0d4ff4..24268e7b3e 100644
--- a/apps/web/ui/auth/register/verify-email-form.tsx
+++ b/apps/web/ui/auth/register/verify-email-form.tsx
@@ -1,12 +1,13 @@
"use client";
import { createUserAccountAction } from "@/lib/actions/create-user-account";
+import { getValidInternalRedirectPath } from "@/lib/middleware/utils/is-valid-internal-redirect";
import { AnimatedSizeContainer, Button, useMediaQuery } from "@dub/ui";
import { cn } from "@dub/utils";
import { OTPInput } from "input-otp";
import { signIn } from "next-auth/react";
import { useAction } from "next-safe-action/hooks";
-import { useRouter } from "next/navigation";
+import { useRouter, useSearchParams } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { useRegisterContext } from "./context";
@@ -14,6 +15,7 @@ import { ResendOtp } from "./resend-otp";
export const VerifyEmailForm = () => {
const router = useRouter();
+ const searchParams = useSearchParams();
const { isMobile } = useMediaQuery();
const [code, setCode] = useState("");
const { email, password } = useRegisterContext();
@@ -31,8 +33,16 @@ export const VerifyEmailForm = () => {
redirect: false,
});
+ // preserve the next query param if present (and valid)
+ const next = getValidInternalRedirectPath({
+ redirectPath: searchParams.get("next"),
+ currentUrl: window.location.href,
+ });
+
if (response?.ok) {
- router.push("/onboarding");
+ router.push(
+ `/onboarding${next ? `?next=${encodeURIComponent(next)}` : ""}`,
+ );
} else {
toast.error(
"Failed to sign in with credentials. Please try again or contact support.",
diff --git a/apps/web/ui/partners/bounties/bounty-description.tsx b/apps/web/ui/partners/bounties/bounty-description.tsx
index ca2771945a..a093e4865b 100644
--- a/apps/web/ui/partners/bounties/bounty-description.tsx
+++ b/apps/web/ui/partners/bounties/bounty-description.tsx
@@ -60,8 +60,8 @@ export function BountyDescription({
<div className="text-content-subtle mt-2 text-sm font-medium leading-5">
{submissionTexts.map((text) => (
- <div className="flex items-center gap-1.5" key={text}>
- <Check2 className="size-3 text-green-600" />
+ <div className="flex items-start gap-1.5" key={text}>
+ <Check2 className="size-3 shrink-0 text-green-600" />
<span>{text}</span>
</div>
))}
@@ -77,8 +77,8 @@ export function BountyDescription({
<div className="text-content-subtle mt-2 text-sm font-medium leading-5">
{rewardTexts.map((text) => (
- <div className="flex items-center gap-1.5" key={text}>
- <Check2 className="size-3 text-green-600" />
+ <div className="flex items-start gap-1.5" key={text}>
+ <Check2 className="size-3 shrink-0 text-green-600" />
<span>{text}</span>
</div>
))}