Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!