Auth0 loginWithPopup() authenticates user but not loginWithRedirect()

Viewed 195

I am setting up Auth0 in a React app and am running into a bit of confusion.

Inside an Auth0 context I defined, I have a function called login:

  const login = async (options) => {

    await auth0Client.loginWithPopup(options); // isAuthenticated() returns true
    // OR
    await auth0Client.loginWithRedirect(options); // isAuthenticated() returns false

    const isAuthenticated = await auth0Client.isAuthenticated();
    console.log(isAuthenticated);

    if (isAuthenticated) {
      const user = await auth0Client.getUser();
      const claims = await auth0Client.getIdTokenClaims();
      const authToken = claims.__raw;

      dispatch({
        type: 'LOGIN',
        payload: {
          authToken,
          user: {
            id: user.sub,
            avatar: user.picture,
            email: user.email,
            name: user.name,
            tier: 'Premium'
          }
        }
      });
    }
  };

In the above function, I currently have auth0Client.loginWithPopup(options) implemented and this works correctly (i.e. auth0Client.isAuthenticated() returns true in the following line which redirects the user into the app).

I would like to use auth0Client.loginWithRedirect(options) instead, but when I run my app with this line, auth0Client.isAuthenticated() returns false and the user isn't redirected away from the login page. The redirect window opens, however, letting me type in my credentials, but once I submit, it goes back to the login page.

Please help! What am I missing here? Thank you in advance.

0 Answers
Related