Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda