mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-26 05:51:17 -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
|
expect(nextAuthMock).toHaveBeenCalledTimes(1); // built at import, never invoked per-request
|
||||||
});
|
});
|
||||||
|
|
||||||
it("404s other auth endpoints when auth is disabled", async () => {
|
it.each([["providers"], ["csrf"], ["signin"]])(
|
||||||
const mod = await import("pages/api/auth/[...nextauth]");
|
"answers the %s endpoint with parseable JSON when auth is disabled",
|
||||||
const end = vi.fn();
|
async (endpoint) => {
|
||||||
const res = { status: vi.fn(() => ({ end, json: vi.fn() })) };
|
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(res.status).toHaveBeenCalledWith(200);
|
||||||
expect(end).toHaveBeenCalled();
|
expect(json).toHaveBeenCalledWith({});
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
it("does not enable NextAuth's raw debug logger", async () => {
|
it("does not enable NextAuth's raw debug logger", async () => {
|
||||||
const mod = await import("pages/api/auth/[...nextauth]");
|
const mod = await import("pages/api/auth/[...nextauth]");
|
||||||
|
|||||||
@@ -155,10 +155,7 @@ const nextAuthHandler = NextAuth(authOptions);
|
|||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Just pass empty session if auth not enabled
|
// Just pass empty session if auth not enabled
|
||||||
if (!authEnabled) {
|
if (!authEnabled) {
|
||||||
if (req.query.nextauth?.[0] === "session") {
|
return res.status(200).json({});
|
||||||
return res.status(200).json({});
|
|
||||||
}
|
|
||||||
return res.status(404).end("Not Found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextAuthHandler(req, res);
|
return nextAuthHandler(req, res);
|
||||||
|
|||||||
Reference in New Issue
Block a user