Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
How can I make a next.js server-side redirect using a query parameter in the original URL?

At the risk of getting pointed to https://xyproblem.info/ I'll start with what I'm trying to do.

I have an OAuth connection on my site to Spotify. It's a simple connection: /page -> www.spotify.com/auth -> /redirect?next=page -> /page

Right now, I'm passing state to the Spotify auth page and then doing a clientside redirect at /redirect. Technically this works but it creates a flash of text on the redirect page that seems totally unnecessary (not to mention extra request to the server).

My solution is to create a server-side redirect at /redirect that reads the query param called "next" and redirects straight to that. When I create the redirect rule though, Next pops out a "invalid url" error with no info about what URL it's trying to construct. Here's what I have in my next config:

  async redirects() {
    return [
      {
        source: '/redirect',
        permanent: false,
        has: [
          {
            type: 'query',
            key: 'state',
            value: '(?<next>.*)',
          }
        ],
        destination: `:next`,
      },
    ]
  },
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!