Multiple Moqui Sessions Created on First Load from Next.js

The Problem:

  • On first load, multiple API calls are made in parallel from different components.
  • Since there’s no session cookie yet, the backend (Moqui) creates a new session for each request.
  • This results in 4–5 separate sessions being created unnecessarily.

What I Need:

  • A way to ensure that all initial requests share the same session, even before the user is authenticated.
  • A recommended pattern (middleware, proxy, etc.) in Next.js to manage and persist the Moqui session cookie for guest users across multiple API calls.

Any suggestions or best practices to handle this cleanly would be greatly appreciated!


Any suggestion?

When multiple users access the Moqui server, the server generates a separate session for each user, right? When you talk about multiple API calls, whether the Moqui server treats them as coming from one user or multiple users is not related to Moqui itself. If you want the server to create only one session for multiple API calls, you need to first make a request to the server to obtain the jsessionid, and then include this jsessionid with all subsequent API calls.

1 Like