# 'user' is undefined and isAuthenticated returns false after login

**URL:** <https://community.auth0.com/t/user-is-undefined-and-isauthenticated-returns-false-after-login/87495>\
**Category:** Get Help\
**Tags:** isauthenticated, react, auth0\
**Created:** [July 22, 2022, 4:57pm UTC](https://community.auth0.com/t/user-is-undefined-and-isauthenticated-returns-false-after-login/87495 "2022-07-22T16:57:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lm2000](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lm2000/32/33204_2.png) [@lm2000](https://community.auth0.com/u/lm2000)\
**Post date:** [July 22, 2022, 4:57pm UTC](https://community.auth0.com/t/user-is-undefined-and-isauthenticated-returns-false-after-login/87495/1 "2022-07-22T16:57:37Z")

</div>

I am able to log in and redirect to my redirectURI path but I get an error “Cannot destructure property ‘name’ of ‘user’ as it is undefined.” and isAuthenticated returns false.  
I have a file where I create the Auth0 provider and set the redirectURI:

```auto
import React from 'react';
import { useNavigate } from 'react-router-dom';
import { Auth0Provider } from '@auth0/auth0-react';

const Auth0ProviderWithHistory = ({ children }) => {
    const domain = process.env.REACT_APP_AUTH0_DOMAIN;
    const clientId = process.env.REACT_APP_AUTH0_CLIENT_ID;

    const history = useNavigate();

    const onRedirectCallback = (appState) => {
        history.push(
            appState && appState.returnTo
                ? appState.returnTo
                : window.location.pathname
        );
    };

    return (
        <Auth0Provider
            domain={domain}
            clientId={clientId}
            redirectUri="http://localhost:3003/workspace"
            onRedirectCallback={onRedirectCallback}
        >
            {children}
        </Auth0Provider>
    );
};

export default Auth0ProviderWithHistory;

```

and this is my login file:

```auto
const LoginButton = () => {
    const { loginWithRedirect } = useAuth0();
    return (
        <div className="App">
            <NavBar />

            <button
                className="btn btn-login"
                onClick={() => loginWithRedirect()}
            >
                Log In
            </button>
        </div>

    );
};

export default LoginButton;

```

I’ve included [http://localhost:3003/workspace](http://localhost:3003/workspace) in my Allowed Callback URLs and Allowed Web Origins. Am I missing anything? Thank you!

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [July 22, 2022, 7:01pm UTC](https://community.auth0.com/t/user-is-undefined-and-isauthenticated-returns-false-after-login/87495/2 "2022-07-22T19:01:32Z")

</div>

Hi @lm2000! I can’t tell from the code snippets you provided, but are you also ensuring that `isLoading` is false with the auth0-react SDK?

According to the [Auth0 React Quickstart](https://auth0.com/docs/quickstart/spa/react/01-login#show-user-profile-information) docs:

> Ensure that the SDK has completed loading before accessing the `isAuthenticated` property, by checking that `isLoading` is `false` .

You can also find an example in the auth0-react SDK docs here: [@auth0/auth0-react](https://auth0.github.io/auth0-react/#getting-started)

---

<div class="post-metadata">

**Author:** ![lm2000](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lm2000/32/33204_2.png) [@lm2000](https://community.auth0.com/u/lm2000)\
**Post date:** [July 25, 2022, 7:04am UTC](https://community.auth0.com/t/user-is-undefined-and-isauthenticated-returns-false-after-login/87495/3 "2022-07-25T07:04:08Z")

</div>

@gparascandolo Thanks for the response! I’ve added that check now so ‘user’ is no longer undefined, but isAuthenticated still returns false. The code for this is below. Would there be a reason for this?

```auto
    const { user, isLoading, isAuthenticated } = useAuth0();

    if (isLoading) {
        console.log("loading");
    }
    else if (!isAuthenticated) {
        console.log("authenticated: ", isAuthenticated);
    }
    else if (!isLoading && isAuthenticated) {
        const { name, picture, email } = user;
        return (
            ...
       )
  }

    

```

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [July 29, 2022, 2:01pm UTC](https://community.auth0.com/t/user-is-undefined-and-isauthenticated-returns-false-after-login/87495/4 "2022-07-29T14:01:22Z")

</div>

Hi @lm2000 , just to confirm - you are saying that you are now seeing a `user` object defined after the update (meaning successful authentication took place), but `isAuthenticated` is still returning false after `isLoading` is false?

No errors coming from the Auth0 logs about invalid callback\_urls in your tenant?

This post by an Auth0 Employee may help you as well if you want to take a look into that - [isAuthenticated always returns false (React) - #2 by Ale](https://community.auth0.com/t/isauthenticated-always-returns-false-react/60039/2)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [October 7, 2022, 8:46pm UTC](https://community.auth0.com/t/user-is-undefined-and-isauthenticated-returns-false-after-login/87495/5 "2022-10-07T20:46:00Z")

</div>

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