diff --git a/packages/better-auth/src/db/schema.ts b/packages/better-auth/src/db/schema.ts index 7166b569..55bb5896 100644 --- a/packages/better-auth/src/db/schema.ts +++ b/packages/better-auth/src/db/schema.ts @@ -1,15 +1,8 @@ -import * as z from "zod"; import type { AuthPluginSchema } from "../types/plugins"; import type { BetterAuthOptions } from "../types/options"; import { APIError } from "better-call"; import type { Account, Session, User } from "../types"; -import { type DBFieldAttribute, coreSchema } from "@better-auth/core/db"; - -export const verificationSchema = coreSchema.extend({ - value: z.string(), - expiresAt: z.date(), - identifier: z.string(), -}); +import type { DBFieldAttribute } from "@better-auth/core/db"; // Cache for parsed schemas to avoid reparsing on every request const cache = new WeakMap< diff --git a/packages/better-auth/src/types/models.ts b/packages/better-auth/src/types/models.ts index 816e8d26..04153e22 100644 --- a/packages/better-auth/src/types/models.ts +++ b/packages/better-auth/src/types/models.ts @@ -1,10 +1,8 @@ import type { BetterAuthOptions } from "./options"; -import type { verificationSchema } from "../db/schema"; import type { Auth } from "../auth"; import type { InferFieldsFromOptions, InferFieldsFromPlugins } from "../db"; import type { StripEmptyObjects, UnionToIntersection } from "./helper"; import type { BetterAuthPlugin } from "./plugins"; -import type * as z from "zod"; import type { User, Session } from "@better-auth/core/db"; export type Models = @@ -85,6 +83,10 @@ interface RateLimit { lastRequest: number; } -export type { User, Account, Session } from "@better-auth/core/db"; -export type Verification = z.infer; +export type { + User, + Account, + Session, + Verification, +} from "@better-auth/core/db"; export type { RateLimit }; diff --git a/packages/core/src/db/index.ts b/packages/core/src/db/index.ts index 1b8ed4ef..2ac26adc 100644 --- a/packages/core/src/db/index.ts +++ b/packages/core/src/db/index.ts @@ -10,6 +10,7 @@ export { coreSchema } from "./schema/shared"; export { userSchema, type User } from "./schema/user"; export { accountSchema, type Account } from "./schema/account"; export { sessionSchema, type Session } from "./schema/session"; +export { verificationSchema, type Verification } from "./schema/verification"; export type { DBFieldAttribute, diff --git a/packages/core/src/db/schema/verification.ts b/packages/core/src/db/schema/verification.ts new file mode 100644 index 00000000..0916e82a --- /dev/null +++ b/packages/core/src/db/schema/verification.ts @@ -0,0 +1,15 @@ +import * as z from "zod"; +import { coreSchema } from "./shared"; + +export const verificationSchema = coreSchema.extend({ + value: z.string(), + expiresAt: z.date(), + identifier: z.string(), +}); + +/** + * Verification schema type used by better-auth, note that it's possible that verification could have additional fields + * + * todo: we should use generics to extend this type with additional fields from plugins and options in the future + */ +export type Verification = z.infer;