# isAuthenticated() is always false

**URL:** <https://community.auth0.com/t/isauthenticated-is-always-false/84794>\
**Category:** Get Help\
**Created:** [June 8, 2022, 9:06am UTC](https://community.auth0.com/t/isauthenticated-is-always-false/84794 "2022-06-08T09:06:21Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![art.stupels](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/art.stupels/32/30429_2.png) [@art.stupels](https://community.auth0.com/u/art.stupels)\
**Post date:** [July 24, 2022, 12:52pm UTC](https://community.auth0.com/t/isauthenticated-is-always-false/84794/3 "2022-07-24T12:52:43Z")

</div>

You will need to use the [auth0.handleRedirectCallback()](https://auth0.github.io/auth0-spa-js/classes/auth0client.html#handleredirectcallback) function to handle success and error responses from Auth0.

```auto
try {
    auth0.isAuthenticated().then(async function (authenticated) {
        if (!authenticated) {
            const query = window.location.search;
            const shouldParseResult = query.includes("code=") && query.includes("state=");
            if (shouldParseResult) {
                console.log("> Parsing redirect");
                try {
                    const result = await auth0.handleRedirectCallback();
                    console.log("Logged in!");
                } catch (err) {
                    console.log("Error parsing redirect:", err);
                }
                window.history.replaceState({}, document.title, "/");
            } else {
                auth0.loginWithRedirect({ redirect_uri: window.location.origin });
            }
        } else {
            auth0.getTokenSilently().then(function (token) {
                Ext.Ajax.setDefaultHeaders({ 'Authorization': 'Bearer ' + token });
            });
        }
    })
} catch (err) {
    console.log("Log in failed", err);
}

```

Alternatively, you can the [useloginWithPopup()](https://auth0.github.io/auth0-spa-js/classes/auth0client.html#loginwithpopup) function:

```auto
if(!authenticated) {                      
    auth0.loginWithPopup().then(token => {
        auth0.getUser().then(user => {
            console.log(user);
        });
    })
 }

```

---

_[View the full topic](https://community.auth0.com/t/isauthenticated-is-always-false/84794)._
