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 I have a question about "Default directory" - in my company we have it setup differently. Where in the cypress code and how that is used? How can I change code to use value from that field?