# Auth0 failing after F5 in React

**URL:** <https://community.auth0.com/t/auth0-failing-after-f5-in-react/186000>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [April 27, 2025, 8:40am UTC](https://community.auth0.com/t/auth0-failing-after-f5-in-react/186000 "2025-04-27T08:40:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EvalVis](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/evalvis/32/74494_2.png) [@EvalVis](https://community.auth0.com/u/EvalVis)\
**Post date:** [April 27, 2025, 8:40am UTC](https://community.auth0.com/t/auth0-failing-after-f5-in-react/186000/1 "2025-04-27T08:40:08Z")

</div>

I have this code:

```auto
import { useState, useEffect } from 'react'
import { useAuth0 } from '@auth0/auth0-react'
import Profile from './components/Profile'
import Login from './components/Login'
import Quotes from './components/Quotes'
import './App.css'

interface Quote {
  quote: string;
  author: string;
  tags: string[];
}

function App() {
  const [quotes, setQuotes] = useState<Quote[]>([])
  const { isAuthenticated, isLoading, getAccessTokenSilently } = useAuth0()

  useEffect(() => {
    if (isAuthenticated) {
      (async () => {
        const token = await getAccessTokenSilently()
      
        const response = await fetch('https://quotesapi.fly.dev/api/quotes/random', {
          headers: {
            Authorization: `Bearer ${token}`
          }
        })
        
        const data = await response.json()
        setQuotes(data)
      })()
    }
  }, [isAuthenticated, getAccessTokenSilently])

  if (isLoading) {
    return <div className="loading">Loading...</div>
  }

  return (
    <div className="app-container">
      <h1>Quotes API</h1>
      
      {isAuthenticated ? (
        <div>
          <Profile />
          {quotes.length > 0 && <Quotes quotes={quotes} />}
        </div>
      ) : (
        <div className="login-container">
          <p>Please log in to see quotes</p>
          <Login />
        </div>
      )}
    </div>
  )
}

export default App

```

Everything is good while I don’t hit the F5, I can login, send token to my BE. The Auth0 session is stored in local memory. On hitting F5 the session is still there however calling /authorize fails with 400 Bad request.

I found one of the solutions: if I add cacheLocation as localStorage like this:

```auto
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { Auth0Provider } from '@auth0/auth0-react'
import './index.css'
import App from './App.tsx'

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <Auth0Provider
      domain="dev-wzfkg4o26oz6ndmt.us.auth0.com"
      clientId="v0YzxpAoJP6tLyW29TnZEuqStYkUF5fY"
      authorizationParams={{
        redirect_uri: window.location.origin,
        audience: "quotes.programmersdiary.com"
      }}
      **cacheLocation="localstorage"**
    >
      <App />
    </Auth0Provider>
  </StrictMode>,
)

```

However if my knowledge is correct using localStorage is discouraged due to XSS attacks.  
Any better way to solve this refresh page problem?

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [April 28, 2025, 11:40am UTC](https://community.auth0.com/t/auth0-failing-after-f5-in-react/186000/2 "2025-04-28T11:40:32Z")

</div>

Hi @EvalVis

Welcome to the Auth0 Community!

Thank you for posting your question. I’ve found the knowledge solution that should probably solve your issue with 400 Bad Request after the user hits F5. Can you try to implement `onRedirectCallback` function in your code → [Auth0ProviderOptions | @auth0/auth0-react](https://auth0.github.io/auth0-react/interfaces/Auth0ProviderOptions.html#onRedirectCallback). You can read more about that here → [State and Code Parameters Stuck in URL react-auth0 - User Getting Logged Out on Page Refresh](https://community.auth0.com/t/state-and-code-parameters-stuck-in-url-react-auth0-user-getting-logged-out-on-page-refresh/148408)

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 12, 2025, 11:40am UTC](https://community.auth0.com/t/auth0-failing-after-f5-in-react/186000/3 "2025-05-12T11:40:34Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
