From e8f94bd8731c91d807ed317595b602693e697e93 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 7 Aug 2026 08:45:38 -0700 Subject: [PATCH] Prevent getProviders issue with auth disabled --- .../pages/api/auth/[...nextauth].test.js | 19 +++++++++++-------- src/pages/api/auth/[...nextauth].js | 5 +---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/__tests__/pages/api/auth/[...nextauth].test.js b/src/__tests__/pages/api/auth/[...nextauth].test.js index 2fac1f734..7e1e7fdfd 100644 --- a/src/__tests__/pages/api/auth/[...nextauth].test.js +++ b/src/__tests__/pages/api/auth/[...nextauth].test.js @@ -50,16 +50,19 @@ describe("pages/api/auth/[...nextauth]", () => { expect(nextAuthMock).toHaveBeenCalledTimes(1); // built at import, never invoked per-request }); - it("404s other auth endpoints when auth is disabled", async () => { - const mod = await import("pages/api/auth/[...nextauth]"); - const end = vi.fn(); - const res = { status: vi.fn(() => ({ end, json: vi.fn() })) }; + it.each([["providers"], ["csrf"], ["signin"]])( + "answers the %s endpoint with parseable JSON when auth is disabled", + async (endpoint) => { + const mod = await import("pages/api/auth/[...nextauth]"); + const json = vi.fn(); + const res = { status: vi.fn(() => ({ json, end: vi.fn() })) }; - await mod.default({ query: { nextauth: ["csrf"] } }, res); + await mod.default({ query: { nextauth: [endpoint] } }, res); - expect(res.status).toHaveBeenCalledWith(404); - expect(end).toHaveBeenCalled(); - }); + expect(res.status).toHaveBeenCalledWith(200); + expect(json).toHaveBeenCalledWith({}); + }, + ); it("does not enable NextAuth's raw debug logger", async () => { const mod = await import("pages/api/auth/[...nextauth]"); diff --git a/src/pages/api/auth/[...nextauth].js b/src/pages/api/auth/[...nextauth].js index 750ee959c..5f35f0579 100644 --- a/src/pages/api/auth/[...nextauth].js +++ b/src/pages/api/auth/[...nextauth].js @@ -155,10 +155,7 @@ const nextAuthHandler = NextAuth(authOptions); export default async function handler(req, res) { // Just pass empty session if auth not enabled if (!authEnabled) { - if (req.query.nextauth?.[0] === "session") { - return res.status(200).json({}); - } - return res.status(404).end("Not Found"); + return res.status(200).json({}); } return nextAuthHandler(req, res);