mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-17 09:35:50 -07:00
Prevent getProviders issue with auth disabled
This commit is contained in:
@@ -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]");
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user