Hi there,
I’m having an issue with the withAuthenticationRequired HOC. It seems not working as expected on production.
I have a protected route (ex: /testpage
). I tried to send the appState on: 'test page'
and want to see it on console.log in function onRedirectCallback()
import { withAuthenticationRequired } from '@auth0/auth0-react';
import PageLoader from '../layouts/PageLoader';
const TestPage: React.FC = () => {
return <div>This is a test auth0 page</div>;
};
export default withAuthenticationRequired(TestPage, {
loginOptions: {
appState: {
on: 'test page',
},
},
returnTo: () => window.location.href,
onRedirecting: () => (
<div className="page-layout">
<PageLoader />
</div>
),
});
const onRedirectCallback = (appState: any) => {
console.log('appState', appState);
router.replace(
appState && appState.returnTo
? appState.returnTo
: window.location.pathname
);
};
Here is the steps on localhost:
- Enter directly
domain/testpage
on address bar and hit enter (still not logged in) - App will redirect to auth0 login page, then log in
- App redirect exactly to /testpage, I can see the result
appState {on: 'test page', returnTo: 'http://localhost:3000/testpage'}
But here is the steps on production:
- Enter directly
domain/testpage
on address bar and hit enter (still not logged in) - App will redirect to my login page (
/
) same as Auth0ProviderredirectUri
prop (I think so) and stay there instead of redirect to auth0 login page
Here is my configuration
//Libs
"@auth0/auth0-react": "^1.12.0",
"next": "12.2.5",
//Auth0Provider config
domain: process.env.NX_AUTH0_DOMAIN || '',
audience: process.env.NX_AUTH0_AUDIENCE || '',
clientId: process.env.NX_AUTH0_CLIENT_ID || '',
redirectUri: process.env.NX_BASE_URI,
connection: process.env.NX_AUTH0_CONNECTION || '',
useRefreshTokens: true,
advancedOptions: {
defaultScope: 'openid profile email offline_access',
},
onRedirectCallback,
Please let my know your opinions. Thank you very much.