# State error with auth0-js and iframe implementation

**URL:** <https://community.auth0.com/t/state-error-with-auth0-js-and-iframe-implementation/64533>\
**Category:** Get Help\
**Created:** [June 15, 2021, 2:52pm UTC](https://community.auth0.com/t/state-error-with-auth0-js-and-iframe-implementation/64533 "2021-06-15T14:52:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas\_sterle](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/thomas_sterle/32/25946_2.png) [@thomas\_sterle](https://community.auth0.com/u/thomas_sterle)\
**Post date:** [June 15, 2021, 2:52pm UTC](https://community.auth0.com/t/state-error-with-auth0-js-and-iframe-implementation/64533/1 "2021-06-15T14:52:49Z")

</div>

Hi There,

I have some difficulty to found an alternative or solution  
I use `"auth0-js": "9.15.0"`.

**My case:**

I use auth0 on my application for authentication with new Auth0 Universal Login and it works.  
The problème is that some customers use iframe in her owns application to use my application.

With new Auth0 Universal Login we can’t use `Disable clickjacking protection for Classic Universal Login` for iframe usecase, so we can’t log with iframe.

For get around the problem i use popup from auth0-js to log user outside the iframe.

**My implementation:**

WebAuth

```auto
      const client = new auth0.WebAuth({
        domain: '[domain]',
        clientID: '[clientID]',
        redirectUri: '[redirectUri]',
        responseType: 'token id_token',
        scope: 'openid profile email',
      }),

```

popup

```auto
client.popup.authorize(
        {
          redirectUri: auth0Store.redirect_base_url + '/auth0?iframe=true',
        },
        function (err, authResult) {
          if (null !== err) {
            //logout
          }
          
          //use authResult.accessToken
        }
);

```

popup close

```auto
client.popup.callback();

```

With iframe and chrome browser my `authResult` is undefined.  
When i try to replace `client.popup.callback()` by `client.parseHash` i have an error

```auto
{
error: invalid_token, 
errorDescription: `state` does not match., 
message: `state` does not match.
}

```

This work with cross domain and Firfox, but doesn’t with Google chrome.  
I think this come from cookie management but i don’t know how to resolve this problem

Thank you in advance for your answer =)

---

<div class="post-metadata">

**Author:** ![GeovannyLopez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/geovannylopez/32/30396_2.png) [@GeovannyLopez](https://community.auth0.com/u/GeovannyLopez)\
**Post date:** [July 6, 2021, 9:25pm UTC](https://community.auth0.com/t/state-error-with-auth0-js-and-iframe-implementation/64533/3 "2021-07-06T21:25:02Z")

</div>

I had the same error, and after some research, I found a closed issue on GitHub:

[Issue #1077](https://github.com/auth0/auth0.js/issues/1077?_pjax=%23js-repo-pjax-container)

And after adding the following to the WebAuth initialization object everything worked fine:

const client = new auth0.WebAuth({  
domain: ‘[domain]’,  
clientID: ‘[clientID]’,  
redirectUri: ‘[redirectUri]’,  
responseType: ‘token id\_token’,  
scope: ‘openid profile email’,  
**\_\_tryLocalStorageFirst: true**  
}),

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 7, 2021, 12:15pm UTC](https://community.auth0.com/t/state-error-with-auth0-js-and-iframe-implementation/64533/4 "2021-07-07T12:15:15Z")

</div>

Thanks for sharing it with the rest of community!

---

<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:** [July 22, 2021, 12:15pm UTC](https://community.auth0.com/t/state-error-with-auth0-js-and-iframe-implementation/64533/5 "2021-07-22T12:15:47Z")

</div>

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