Since writing this gist, sir-dunxalot/cypress-nextjs-auth0 was released, which encapsulates this gist in a more user-friendly way. Try it out:
yarn add cypress-nextjs-auth0 --dev
A walkthrough is covered in this blog post.
- You need to enable the
password
grant type in your Auth0 application's settings - You need to set the default directory (in your Auth0 tenant settings) to
Username-Password-Authentication
, which is usually the name of the database connection you want to use forpassword
grant authentication (the name will be shown in Auth0 Dashboard --> Connections --> Database). - The username and password combination should be a real user (albeit one you create for testing only)
- This method skips token verification and reveals secrets, but I am assuming I can reduce security in my test environment
- Auth0 recommends you use seperate tenants for development, testing, and production
- If this setup fails, you may need to add
"chromeWebSecurity": false
to yourcypress.json
config file.
@sir-dunxalot thank you so much for making this. I do have one more question though. I am using the @auth0/auth0-react package which uses the Auth0Provider. This seems to be have a unique name for the cookie being created so although your code does authenticate and creates a session I'm still getting redirected. I was wondering if you knew what the cookie name should be as well as anything else that may be needed.