Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda