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

179
Vistas
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 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