Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eleven-spiders-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"better-auth-convex": patch
---

fix: map Convex table names to Better Auth model keys in isUniqueField
16 changes: 11 additions & 5 deletions src/adapterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,20 @@ const isUniqueField = (
model: string,
field: string
) => {
const fields =
betterAuthSchema[model as keyof typeof betterAuthSchema].fields;

if (!fields) {
// Map Convex table name (e.g., "users") to Better Auth model key (e.g., "user")
// by finding the key where betterAuthSchema[key].modelName === model
const betterAuthModel =
Object.keys(betterAuthSchema).find(
(key) => betterAuthSchema[key as keyof typeof betterAuthSchema].modelName === model
) || model;
const modelSchema =
betterAuthSchema[betterAuthModel as keyof typeof betterAuthSchema];

if (!modelSchema?.fields) {
return false;
}

return Object.entries(fields)
return Object.entries(modelSchema.fields)
.filter(([, value]) => value.unique)
.map(([key]) => key)
.includes(field);
Expand Down