End-to-End Testing with Cypress and Auth0

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?

1 Like

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 How to test single page application with Cypress and Auth0 - Stack Overflow
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.

Hi, I followed this article to retrieve Auth0 token_id and access_token, but unfortunately it does not seem to work with @auth0/auth0-react@1.9.x. Can someone provide some help? Thanks.


We are writing e2e tests for our SPA (it uses the @auth0/auth0-react library). We are hoping we can run them against our dev and production environments. We are following the blog post and have created a separate client for the tests that uses the “password” grant type. The tests call /oauth/token and receive the access token and ID token. We are hoping we can send this information to our react SPA. We ended up writing something very similar to dobrek’s solution - after getting the tokens from /oauth/token, we redirect to the react app and set the tokens in local storage. However, calling the API with the access token fails because it’s expecting a signed JWT. Is it possible for the token endpoint to return a signed token? Would it even work if it’s signed by one client (my e2e tests), but used by another client (the react app in dev/production)?


@robertino.calcaterra would you be able to follow up on this? Thank you!

We are working on this @konrad.sopala (cc @nancy.habecker)

1 Like

Is it possible for the token endpoint to return a signed token?

Yes, you will get a JWT Access Token if you specify an audience in the /oauth/token request. See the difference between Opaque and JWT access tokens here: Access Tokens also Call Your API Using Resource Owner Password Flow

Would it even work if it’s signed by one client (my e2e tests), but used by another client (the react app in dev/production)?

Yes, the authorization server signs the JWT, it doesn’t matter to your API which client is bearing the access token.

1 Like

It’s a good start but I need more info. In my case I use auth0-react and the Auth0Provider JSX component. This component causes a redirect to login, when user hits a page when they are not logged in.
I need to know the cookies that are needing to be set to make this component accept that a valid login has been completed. I thought I could just set the auth0.is.authenticated cookie but that is not sufficient and redirect is still happening.
Does anyone know what those cookie names and values should be while using Cypress?

I use @auth0/auth0-react and useAuth0 -

I don’t want to add “authService.send(“AUTH0”, { user, token })” and change my working application code exclusively for e2e purposes (unless I have to).

I am successfully retrieving a token via the commands.js oauth/token flows…but I have been unable to figure out how to make that work with const { user, isAuthenticated, isLoading, getAccessTokenSilently} = useAuth0();

“We are positioning this topic internally as a high-priority topic” from @dan-auth0 is from 3/2020 -

When convenient, please advise.

@konrad.sopala @robertino.calcaterra

Just a heads up that interactive logins will soon be supported in Cypress via https://github.com/cypress-io/cypress/pull/18075

All of the core features are finished, so I believe this will be in a upcoming release.

1 Like