Callback handler fail 400 Bad request with NextJS

Problem statement

Navigate to login from the unauthenticated page fails

Symptoms

  1. The /api/auth/callback is showing a Chrome error “net::ERR_HTTP_RESPONSE_CODE_FAILURE” a few milliseconds after, so a timeout is discarded.
  2. LoginHandlerError: Login handler failed.
  3. CallbackHandlerError: Callback handler failed.
  4. 400 Bad request

Steps to reproduce

  1. Go to the unauthenticated page
  2. Login

Troubleshooting

  • HAR file
  • Debug the application to analyze step-by-step behavior (see-through objects received in each step, check differences with the Sample behavior, etc.)
  • Provide replication steps

Cause

Library was @adobe/aem-headless-client-nodejs

Solution

Replace it with@adobe/aem-headless-client-js