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
6 changes: 6 additions & 0 deletions .changeset/better-auth-type-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@proofkit/better-auth": patch
---

Fix TypeScript build errors by making adapter/migration types resilient to upstream Better Auth changes.

18 changes: 12 additions & 6 deletions packages/better-auth/src/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import type { createRawFetch } from "./odata";
/** Schema type returned by better-auth's getSchema function */
type BetterAuthSchema = Record<string, { fields: Record<string, DBFieldAttribute>; order: number }>;

function normalizeBetterAuthFieldType(fieldType: unknown): string {
if (typeof fieldType === "string") return fieldType;
if (Array.isArray(fieldType)) return fieldType.map(String).join("|");
return String(fieldType);
}

export async function getMetadata(fetch: ReturnType<typeof createRawFetch>["fetch"], databaseName: string) {
console.log("getting metadata...");
const result = await fetch("/$metadata", {
Expand Down Expand Up @@ -96,12 +102,12 @@ export async function planMigration(

for (const baTable of baTables) {
const fields: FmField[] = Object.entries(baTable.fields).map(([key, field]) => {
let type: "varchar" | "numeric" | "timestamp" = "varchar";
if (field.type === "boolean" || field.type.includes("number")) {
type = "numeric";
} else if (field.type === "date") {
type = "timestamp";
}
// Better Auth's FieldType can be a string literal union or arrays.
// Normalize it to a string so our FM mapping logic remains stable.
// Use .includes() for all checks to handle array types like ["boolean", "null"] → "boolean|null"
const t = normalizeBetterAuthFieldType(field.type);
const type: "varchar" | "numeric" | "timestamp" =
t.includes("boolean") || t.includes("number") ? "numeric" : t.includes("date") ? "timestamp" : "varchar";
return {
name: field.fieldName ?? key,
type,
Expand Down
Loading