Auth0 Home Blog Docs

How to trigger autologin with react


I have been following the auth0 react series and it works great but I am wondering if someone can tell me how to set up an autologin of auth0 when the person hits the page. The behavior is that when someone hits a page and they are not logged in, it should redirect to the following page:

class Home extends React.Component {
  componentDidMount() {
    const { user, auth } = this.props;
    if (!auth.isAuthenticated() ) {

  componentDidUpdate() {
    const { user, auth } = this.props;

  render() {
    return null;

The idea is that if they aren’t logged in, call the login method. The problem is that auth0 directs me off the page, so that the componentDidMount triggers after the successful log in which then triggers the auth.login() all over again. What I need to happen is to have the auth.login() to not run when I get redirected back to my page and instead just hang tight for a componentDidUpdate which will call a custom method I have which will redirect to the desired page based on the user’s preference.

I think the main issue, is how can I cause react to just chill for a second after the auth0 login and a redirect to the home page before trying to access the local storage jwt. Any tips on how to do that?



Hey @stephen.jensen.ihi!

As it has been more than a few months since this topic was opened and there has been no reply or further information provided from the community as to the existence of the issue we would like to check if you are still facing the described challenge?

We are more than happy to assist in any way! If the issue is still out there please let us know so we can create a new thread for better visibility, otherwise we’ll close this one in week’s time.

Thank you!

closed #4

This topic was automatically closed after 5 days. New replies are no longer allowed.