Skip to content

AuthPlugin should be loaded in both server and MSW modes, and gracefully handle missing HTTP server (support universal auth endpoints simulation) #862

Description

@hotlong

Problem

Currently, ObjectStack runtime (in both server and MSW/mock modes) does NOT load AuthPlugin by default in the kernel or in the configuration of most app examples (e.g., objectstack-ai/objectui, etc).

  • In server mode (HonoServerPlugin active), AuthPlugin works and registers /api/v1/auth/* endpoints and integrates better-auth backend.
  • In MSW/mock mode (pnpm dev), the kernel does not load AuthPlugin at all, and HttpDispatcher.handleAuth() cannot simulate /api/v1/auth/* endpoints, leading to 404 errors for registration and sign-in flows.
  • There is no fallback built into runtime for better-auth endpoints when AuthPlugin is not present.

Expected

  • AuthPlugin is loaded in both server and MSW/browser test environments wherever user authentication is needed.
  • In MSW mode, AuthPlugin should gracefully skip HTTP route registration if HonoServerPlugin/http-server is missing, BUT it should still register the 'auth' service so HttpDispatcher.handleAuth() can mock/simulate auth flows (sign-up, sign-in, etc.) using in-memory ObjectQL.
  • Most app scaffolds (.config.ts and kernel factories) should include AuthPlugin by default (unless explicitly testing an unauthenticated app).
  • As fallback for legacy cases, HttpDispatcher.handleAuth() should provide a mock implementation for core better-auth endpoints if AuthPlugin is missing (for high-fidelity MSW mock environments).

Solution

  • Update AuthPlugin to make route registration optional/graceful when no HonoServer/http-server is available (allow mock/test environments to proceed without errors).
  • Update kernal factories (e.g., in objectui, studio, etc) and config scaffolds to include AuthPlugin by DEFAULT.
  • Document MSW/mock usage patterns with AuthPlugin, and clarify minimal required configuration for mock mode (secret, ObjectQL driver, etc).
  • Optionally: extend HttpDispatcher.handleAuth() to provide safe mock fallback for registration/sign-in flows if 'auth' service is not present.

Impact

  • Developers can run server OR pnpm dev (MSW mode) and still register/authenticate test users (sign-up, sign-in, sign-out, get-session, etc.).
  • End users no longer encounter 404s for registration flows in Mock Console.

Please see details in objectstack-ai/objectui issue for how the frontend expects MSW mode to behave.

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions