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

209
Vistas
Is it possible to set localstorage from backend to frontend react js?

I am creating an affiliate functionality on my eCommerce website, I have created link generate functionality, My main concept is if any user buys anything from the generated links the main user who created the URL will get a commission. I cannot be able to store the short generated links in the local storage of a user since when they click on these generated links, they are redirected directly to the targeted page. so I am trying to get the short generated URL from my node js backend. I am using node-localstorage package but it not working.

My expectation is when a user clicks on the generated short link, the generated link will be stored into the local storage anyhow from the frontend or backend.

Please note: the generated link will be shared on many platforms so I want before the user goes to the targeted page the short link will be stored into the local storage because if the user goes to the targeted page the short URL is removed automatically.

This is my frontend code: before executing this useEffect the backend redirects to the targeted page.

useLayoutEffect(() => {
        setLoadings(true)
        fetch(`http://localhost:5000/findUrl/${path}`)
            .then(res => res.json())
            .then(data => {
                if (data.isUrlTrue) {
                    localStorage.setItem('affiliate', path)
                }
            })
            .finally(() => setLoadings(false))
    }, [path])

This is my backend code which is not working.

  app.get('/:shortUrl', async (req, res) => {
            const shortenUrl = await bicycleAffiliateLinksCollection.findOne({ short: req.params.shortUrl })
            if (shortenUrl === null) return res.sendStatus(404)
            // shortenUrl.clicks++
            // shortenUrl.save()

            localStorage.setItem('affliate', "asdasd");
            res.redirect(shortenUrl.full)
        })


about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Store the short URL in the local storage before the browser follows the link:

<a href="short_url" onclick='localStorage.setItem("affiliate","short_url")'>Buy it!</a>
about 4 years ago · Juan Pablo Isaza Denunciar
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