createAuth0Client takes 5+ seconds after login from redirect

@auth0/auth0-spa-js createAuth0Client method takes over 5 seconds to complete every time a user logs in. Even after waiting, getTokenSiliently also takes another 5 seconds. That seems ridiculous on a high speed internet, is it normal? (code below, please excuse the lazy perf checking)

The provider is passed proper credentials, redirect_uri

  useEffect(() => {
    const initAuth0 = async () => {
      console.log('I still run!!!')
      const now = Date.now();
      console.log('starting login', now);
      const auth0FromHook = await createAuth0Client(initOptions);
      console.log('created client', Date.now() - now)
      setAuth0(auth0FromHook);

      if (window.location.search.includes('code=')) {
        console.log('calling redirect')
        const { appState } = await auth0FromHook.handleRedirectCallback();
        onRedirectCallback(appState);
      }

      const isAuthenticatedP = auth0FromHook.isAuthenticated();
      const tokenP = auth0FromHook.getTokenSilently();
      const isAuthenticated = await isAuthenticatedP;
      console.log('is authenticated', isAuthenticated, Date.now() - now);

      setIsAuthenticated(isAuthenticated);

      if (isAuthenticated) {
        const token = await tokenP;
        const user = await auth0FromHook.getUser();
        console.log('got tokes', Date.now() - now);
        const meteorStart = Date.now();
        console.log('starting call to meteor login', meteorStart);

        Meteor.loginWithIntelage({ token }, () => {
          const meteorUser = Meteor.user();
          const combinedUserData = { ...user, ...meteorUser };
          console.log('finish call to meteor', Date.now() - meteorStart);
          console.log('metoer user', meteorUser, loggingIn);
          console.log('user', user);
          setUser(combinedUserData);
          setLoading(false);
        });
      } else {
        // redirect
        console.log('redirecting!')
        auth0FromHook.loginWithRedirect({});
      }
      console.log('finish auth', Date.now() - now);
    };
    initAuth0();
  }, []);
2 Likes

Additional details:

Its very slow only on login from a redirect, if the user already has the cookie required, it usually takes like 1/2 a second to do what takes 5 or 10 seconds after redirecting from our universal login page.

Update for others: I’ve been working on this with @goofiw in a support ticket as well. I think we narrowed the issue down to this change:

https://github.com/auth0/auth0-spa-js/pull/238

This is a change to prevent a race condition and it’s only supposed to hold up the application until it can get the token from the cache. For some reason we’re getting the full 5 second timeout in this case. Continuing to investigate. If you’ve experienced this problem please share here.

1 Like

Thanks @matt.macadam for letting us know!

@matt.mcadam I am also experiencing this in my app in the same circumstances as @goofiw. The delay is consistently around 5 seconds. Any known workarounds?

I am using the Universal Login with passwordless authentication and just changed to use a magic link instead of a code. This eliminates the problem.

1 Like

Thanks a lot for sharing it with the rest of community @ddewinter!

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