fix: log error when misconfigured (#7584)

This commit is contained in:
Alex Yang
2026-01-23 17:52:30 -08:00
committed by GitHub
parent bad586a512
commit 10690f4f3c
2 changed files with 17 additions and 0 deletions

View File

@@ -595,6 +595,7 @@ describe("base context creation", () => {
});
it("should return false when generateId is false", async () => {
const fn = vi.spyOn(console, "error").mockImplementation(vi.fn());
const res = await initBase({
advanced: {
database: {
@@ -602,6 +603,10 @@ describe("base context creation", () => {
},
},
});
expect(fn).toHaveBeenCalled();
const regex = /Misconfiguration detected/;
expect(fn).toHaveBeenCalledWith(expect.stringMatching(regex));
fn.mockRestore();
const id = res.generateId({ model: "user" });
expect(id).toBe(false);
});

View File

@@ -112,6 +112,18 @@ export async function createAuthContext(
);
}
if (
adapter.id === "memory" &&
options.advanced?.database?.generateId === false
) {
logger.error(
`[better-auth] Misconfiguration detected.
You are using the memory DB with generateId: false.
This will cause no id to be generated for any model.
Most of the features of Better Auth will not work correctly.`,
);
}
const secret =
options.secret ||
env.BETTER_AUTH_SECRET ||