mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-19 11:24:57 -05:00
Revert "fix(prisma-adapter): don't treat a null unique field as an update selector"
A null unique selector should keep failing instead of falling back to updateMany, which can change several rows on providers that allow multiple NULLs in a unique column.
This commit is contained in:
@@ -300,35 +300,6 @@ describe("prisma-adapter", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to updateMany for `eq null` on a unique field", async () => {
|
||||
const update = vi.fn();
|
||||
const updateMany = vi.fn().mockResolvedValue({ count: 1 });
|
||||
const findFirst = vi.fn().mockResolvedValue({ id: "user-id" });
|
||||
const adapter = prismaAdapter(
|
||||
{ $transaction: vi.fn(), user: { findFirst, update, updateMany } },
|
||||
{ provider: "mongodb" },
|
||||
)({
|
||||
user: {
|
||||
additionalFields: {
|
||||
username: { type: "string", unique: true, required: false },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await adapter.update({
|
||||
model: "user",
|
||||
where: [{ field: "username", operator: "eq", value: null }],
|
||||
update: { name: "Updated" },
|
||||
});
|
||||
|
||||
expect(update).not.toHaveBeenCalled();
|
||||
expect(updateMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { OR: [{ username: null }, { username: { isSet: false } }] },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("should use update (not updateMany) for insensitive mode on unsupported providers", async () => {
|
||||
const update = vi.fn().mockResolvedValue({
|
||||
id: "user-id",
|
||||
|
||||
@@ -219,11 +219,7 @@ export const prismaAdapter = (prisma: PrismaClient, config: PrismaConfig) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
// A unique selector can't be null in Prisma's `WhereUniqueInput`.
|
||||
if (
|
||||
(condition.operator && condition.operator !== "eq") ||
|
||||
condition.value === null
|
||||
) {
|
||||
if (condition.operator && condition.operator !== "eq") {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user