Next.js - Mocking the Session Cookie for Testing

Last Updated: Oct 31, 2024

Overview

The user is building a Next.js application with protected pages and API routes and is looking for guidance on how to completely isolate the automated test from Auth0.
Is it possible to generate a mock appSession cookie to be used for test purposes?

Applies To

  • Next.js application
  • Session Cookie

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: