Next.js - Mocking the Session Cookie for Testing

Problem statement

We are building a Next.js application with protected pages and API routes. We are looking for guidance on how to completely isolate automated test from Auth0.

Is it possible to generate a mock appSession cookie to be used for test purposes?

Solution

The appSession cookie should be used by the SDK to establish a local session and avoid needing to call the Auth0 endpoints unnecessarily. For mocking the session cookie, use this utility to mock the Auth0 authentication flow for E2E tests:

There is also some more general testing advice for the Next.js SDK here: