End-to-End Testing with Cypress and Auth0

Glad to hear that @matinfo!

I’m using auth0-react hook useAuth0.
I successfully get the access_token, expires_in, and id_token, but I could use some guidance on how to use them to actually have the hook/Auth0Provider detect those and set the required variables.


1 Like

I’m trying to login to auth0 during a cypress test using auth0-react. I’ve followed this guide -

That guide does not use auth0-react and has a custom state/auth handler which updates once the { access_token, expires_in, id_token } are received.

Is there any simple way to update the auth0-react login state once the tokens are received?

Ideally, I’d be able to use some endpoint to receive the usual code which is given when logging in with the UI. For example, receive code xxx and redirect to:


auth0-react would then update the login state automatically when it parses the URL.

Someone asks the same question in a comment on the post but there isn’t a response:

"I would like to be able to implement a Cypress “login” command that exercises my callback with a code (i.e. authorization code) that would typically be acquired via OAuth exchange. Is there an Auth0 API endpoint that allows me to get a code that I can then use for my callback e.g. https://mydomain.com/callback?code=abcd1234?"

Any ideas?


Moving your message here as this thread is for issues and questions regarding this blog article. Thank you!

1 Like

I’m looking to do the same. Did you find solution with auth0-react?

Not sure if this will be helpful to some other people.

To get this working inside our application (we’re using auth0-react, although this is irrelevant), I ended up making a separate auth0 app for testing that allows login via password grant. I then implemented a solution very similar to what was suggested here End-to-End Testing with Cypress and Auth0

I set the cache mechanism for auth0-react via ENV var, and set it to localstorage before starting the server for cypress tests. I make a login call to auth0 in a before hook, and save the localstorage state and restore it in beforeEach hooks to avoid having to make multiple calls to auth0.

1 Like

Thanks a lot for sharing that with the rest of community @tallyoh!

I wanted to follow up and let everyone know that we are working on a new version. I’ll be sure to share more details as they become available! Stay tuned :slightly_smiling_face:


@James.Morrison maybe you now when the new version of the tutorial will be available?

1 Like

No firm ETA as of yet for release but once it’s finished and it becomes available I will share it here first!


Heads up that Cypress now has a WIP guide for testing with Auth0:

I’d imagine the solution outlined isn’t suitable for every scenario, but it’s a good start.


Hey @tyler3, did you find a solution for this already? Did you by any chance experiment with guardian.js already?

I am now trying this but does it work with multi-factor authentication too?

Hey there @chikathreesix!

Moving it here as that thread stores all the questions related to this blog article.

Thanks, @konrad.sopala !


Trying to implement Cypress tests with only social connection logins. Is it feasible? If yes, do you have any pointers on that?


@dunson062786, thank you for sharing repo. I was trying to understand a real problem for my app and found that I failed requests because after completing all steps the local storage had only one token (id_token) and i missed 2nd token :frowning: Our implementation is required to get +acces_token and now it’s a real challenge for me.

I’ll check @dobrek solution. Perhaps it will work with the last update and local storage :expressionless:

@stefanos, check https://stackoverflow.com/a/62436606/11032781
If google is in scope of your ‘social connections’ you can check the source :wink:
Good luck.

1 Like

Thanks for sharing that @RoDen!

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