title: react-oidc-context redirects to originating route after successful login with auth0
body: <p>Hi I'm trying to use react-oidc-context to authenticate with auth0 and I have one problem. After successful authentication with auth0 I always get redirected back to the route I was on when I clicked the login button. The app has 2 unprotected routes /login and /public and I could be on either of those when I click login in the page header. I always get redirected to whichever of these pages I was on initially. The login button calls login from the useReactOidc hook. I want to be redirected to the /home route and have tried doing a history.push('/home') before calling login() but no luck.</p>
  <p>In the case of the login page I could include logic to redirect to /home if we're logged in as we don't need to be there, but in the case of /public you could have a reason to be on the page if logged in or not.</p>
  <p>I'm not really getting how the redirect_uri in the configuration fits into this, I've tried setting up a route for this but it never matches (&lt;SecuredRoute path='/authentication/callback' ...). If anyone has any suggestions for how to redirect to a specific route upon successful login it would be greatfully appreciated, hopefully I've just missed something obvious. Thanks and here's the code:</p>
  <p>configuration.js</p>
  <pre><code>const tenancy = 'https://dev-xxxxxxxxxxxxxx.eu.auth0.com';
  const clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  
  export const configuration = {
    client_name: 'My App',
    client_id: clientId,
    scope: 'openid profile',
    response_type: 'code',
    authority: `${tenancy}`,
    redirect_uri: 'http://localhost:3000/authentication/callback',
    // post_logout_redirect_uri: 'http://localhost:3000', // Auth0 uses returnTo
    silent_redirect_uri: 'http://localhost:3000/authentication/silent_callback',
    automaticSilentRenew: true,
    loadUserInfo: true,
    metadata: {
      issuer: `${tenancy}/`,
      authorization_endpoint: `${tenancy}/authorize`,
      token_endpoint: `${tenancy}/oauth/token`,
      userinfo_endpoint: `${tenancy}/userinfo`,
      end_session_endpoint: `${tenancy}/v2/logout?returnTo=${encodeURIComponent('http://localhost:3000')}&amp;client_id=${clientId}`
    }
  };
  </code></pre>
  <p>index.js</p>
  <pre><code>import React from 'react';
  import ReactDOM from 'react-dom';
  import './index.css';
  import App from './App';
  import reportWebVitals from './reportWebVitals';
  import { AuthenticationProvider, oidcLog, InMemoryWebStorage } from '@axa-fr/react-oidc-context';
  import { configuration } from './configuration';
  
  ReactDOM.render(
    &lt;React.StrictMode&gt;
      &lt;AuthenticationProvider
        configuration={configuration}
        loggerLevel={oidcLog.DEBUG}
        isEnabled={true}
        callbackComponentOverride={() =&gt; (&lt;&gt;&lt;/&gt;)}
        UserStore={InMemoryWebStorage}&gt;
        &lt;App /&gt;
      &lt;/AuthenticationProvider&gt;
    &lt;/React.StrictMode&gt;,
    document.getElementById('root')
  );
  </code></pre>
  <p>App.js</p>
  <pre><code>import React from 'react';
  import { useReactOidc } from '@axa-fr/react-oidc-context';
  import { BrowserRouter as Router, Link, Redirect, Route, Switch } from 'react-router-dom';
  import SecuredRoute from './SecuredRoute';
  import { PageHeader, Space } from 'antd';
  
  import './App.css';
  
  const Login = () =&gt; &lt;h3&gt;Login Page - use the Login button top right&lt;/h3&gt;;
  const Home = () =&gt; &lt;h3&gt;Home Page&lt;/h3&gt;;
  const Public = () =&gt; &lt;h3&gt;Public Page&lt;/h3&gt;;
  
  const Header = () =&gt; {
    const { oidcUser, login, logout } = useReactOidc();
  
    return (
      &lt;PageHeader style={{ textAlign: &quot;right&quot;, margin: &quot;8px&quot; }}&gt;
        { oidcUser ? (
          &lt;button onClick={logout}&gt;Log Out&lt;/button&gt;
        ) : (
            &lt;button onClick={login}&gt;Log in&lt;/button&gt;
          )}
      &lt;/PageHeader&gt;
    );
  };
  
  const DefaultPage = () =&gt; {
    const { oidcUser } = useReactOidc();
  
    return (
      oidcUser ? (
        &lt;Redirect to=&quot;/home&quot; /&gt;
        ) : (
        &lt;Redirect to=&quot;/login&quot; /&gt;
      )
    );
  };
  
  const App = () =&gt; {
    return (
      &lt;div className=&quot;App&quot;&gt;
        &lt;Router&gt;
          &lt;Header /&gt;
          &lt;Switch&gt;
            &lt;Route path='/' exact component={DefaultPage} /&gt;
            &lt;Route path='/login' component={Login} /&gt;
            &lt;Route path='/public' component={Public} /&gt;
            &lt;SecuredRoute path='/home' component={Home} /&gt;
            &lt;SecuredRoute path='/authentication/callback' component={Home} /&gt;
          &lt;/Switch&gt;
          &lt;Space&gt;
            &lt;Link to=&quot;/home&quot;&gt;Home Page (you must be logged in to access this)&lt;/Link&gt;
            &lt;br/&gt;
            &lt;Link to=&quot;/public&quot;&gt;Public Page (you don't need to be logged in to access this)&lt;/Link&gt;
          &lt;/Space&gt;
        &lt;/Router&gt;
      &lt;/div&gt;
    );
  };
  
  export default App;
  </code></pre>
  <p>SecuredRoute.js</p>
  <pre><code>import React from 'react';
  import { Redirect, Route } from 'react-router-dom';
  import { useReactOidc } from '@axa-fr/react-oidc-context';
  
  const SecuredRoute = ({ component: Component, ...rest }) =&gt; {
    const { oidcUser } = useReactOidc();
    
    return (
      &lt;Route {...rest} render={(props) =&gt; (
        oidcUser
          ? &lt;Component {...props} /&gt;
          : &lt;Redirect to={{ pathname: '/', state: { from: props.location }}} /&gt;
      )} /&gt;
    );
  };
  </code></pre>
  <p>export default SecuredRoute;</p>
  <p>Versions</p>
  <pre><code>&quot;dependencies&quot;: {
  &quot;@axa-fr/react-oidc-context&quot;: &quot;^3.1.6&quot;,
  &quot;@axa-fr/react-oidc-context-fetch&quot;: &quot;^3.1.6&quot;,
  &quot;@testing-library/jest-dom&quot;: &quot;^5.11.5&quot;,
  &quot;@testing-library/react&quot;: &quot;^11.1.1&quot;,
  &quot;@testing-library/user-event&quot;: &quot;^12.2.0&quot;,
  &quot;antd&quot;: &quot;^4.8.0&quot;,
  &quot;oidc-client&quot;: &quot;^1.10.1&quot;,
  &quot;react&quot;: &quot;^17.0.1&quot;,
  &quot;react-dom&quot;: &quot;^17.0.1&quot;,
  &quot;react-router-dom&quot;: &quot;^5.2.0&quot;,
  &quot;react-scripts&quot;: &quot;4.0.0&quot;,
  &quot;web-vitals&quot;: &quot;^0.2.4&quot;
  },
  </code></pre>