#Stripe Checkout Redirects in Next.js 16

1 messages · Page 1 of 1 (latest)

median gyro
#

Stripe Checkout Redirects in Next.js 15

Hey everyone! I'm integrating Stripe Checkout with Next.js 16 and need help with the best approach for handling redirects.

Use case:
Users can click "Upgrade" from multiple pages (/settings, /pricing)
After clicking, they go to Stripe Checkout
When they click the back arrow on Stripe, I want them to return to the page they came from
The Stripe cancel_url needs to be dynamic based on the originating page

What I’ve tried:

1. Route Handler returning JSON

// API route returns: { url: stripeCheckoutUrl }
// Client fetches, then navigates: window.location.href = url
// Pass returnUrl via query param

2. Server Action with redirect()

'use server'
export async function createCheckout() {
  const session = await stripe.checkout.sessions.create({...})
  redirect(session.url!)
}

The problem: With Server Actions using redirect(), the redirect enters browser history. When users click back from Stripe, they hit the server action again and get redirected elsewhere.

Questions:

  1. What’s the 2025 recommended pattern for dynamic cancel URLs?
  2. Should I stick with Route Handlers returning JSON to avoid history pollution?
  3. Or is there a way to use Server Actions that won’t pollute browser history?

Thanks!

hasty topazBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

median gyro
#

Stripe Checkout Redirects in Next.js 15

#

Stripe Checkout Redirects in Next.js 16