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

180
Visualizações
Component mounted twice on page refresh when using localstorage for Auth0

For some reason, when using cacheLocation='localstorage' for Auth0, a page refresh in our app is causing a call to happen twice...

enter image description here Without localstorage it works fine...

enter image description here

We're using localstorage when running Cypress tests as the page redirect at login doesn't work without it.

The duplication does not happen when first logging in, just on subsequent page refreshes when logged in. Removing the comment in the below code duplicates the call as in the first screenshot...

return (
    <Auth0Provider
        domain={process.env...}
        clientId={process.env...}
        redirectUri={
            typeof window !== 'undefined' ? window.location.origin : `http://localhost:3000`
        }
        onRedirectCallback={onRedirectCallback}
        audience={process.env...}
        //cacheLocation='localstorage'
    >
        <UserInfoProvider>
            <PubSubProvider>
                <StackedLayout>
                    <Component {...pageProps} />
                </StackedLayout>
            </PubSubProvider>
        </UserInfoProvider>
    </Auth0Provider>
)

Edit: Below is a relevant snippet of the page code...

let [searchState, setSearchState] = useState()
const router = useRouter()
const [data, setData] = useState()
const [error, setError] = useState()
const [references, setReferences] = useState({})
const {getAccessTokenSilently} = useAuth0()

useEffect(() => {
const fetchData = async () => {
  setData(null)
  setError(null)

  const accessToken = await getAccessTokenSilently()
  const res = await fetch(
    `${props.apiBaseHref}?${new 
    URLSearchParams(props.query).toString()}`,
    {
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${accessToken}`
      }
    }
  )

  if (!res.ok) {
    setError('some error')
  } else {
    setData(await (res.json()))
  }
}

setSearchState({ ...props.query })
fetchData()
}, [props.apiBaseHref, props.query, getAccessTokenSilently])
about 4 years ago · Juan Pablo Isaza
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