We are hosting a React application in S3 via a Cloudfront distribution. The Cloudfront distribution uses a Lambda@Edge script to forward unauthenticated users to Auth0.
Once authenticated, they are redirected to the React application.
The Cloudfront distribution and React application live in the same subdomain and thus we have access to the JWT (currently being set in a cookie).
We would like to ‘automatically’ hydrate the session in the React app and have tried code similar to the following:
// component ...
const { loginWithRedirect, isAuthenticated } = useAuth0();
useEffect(() => {
if (!isAuthenticated) {
loginWithRedirect();
}
}, [isAuthenticated, loginWithRedirect]);
// component ...
And it seems to work – however once the loginWithRedirect() method finishes – the application continually refreshes – as if isAuthenticated is never set.
Any thoughts?
