refactor: move verification schema to core

This commit is contained in:
Alex Yang
2025-10-02 11:53:38 -07:00
parent 132219b61c
commit affe7722c9
4 changed files with 23 additions and 12 deletions

View File

@@ -1,15 +1,8 @@
import * as z from "zod";
import type { AuthPluginSchema } from "../types/plugins"; import type { AuthPluginSchema } from "../types/plugins";
import type { BetterAuthOptions } from "../types/options"; import type { BetterAuthOptions } from "../types/options";
import { APIError } from "better-call"; import { APIError } from "better-call";
import type { Account, Session, User } from "../types"; import type { Account, Session, User } from "../types";
import { type DBFieldAttribute, coreSchema } from "@better-auth/core/db"; import type { DBFieldAttribute } from "@better-auth/core/db";
export const verificationSchema = coreSchema.extend({
value: z.string(),
expiresAt: z.date(),
identifier: z.string(),
});
// Cache for parsed schemas to avoid reparsing on every request // Cache for parsed schemas to avoid reparsing on every request
const cache = new WeakMap< const cache = new WeakMap<

View File

@@ -1,10 +1,8 @@
import type { BetterAuthOptions } from "./options"; import type { BetterAuthOptions } from "./options";
import type { verificationSchema } from "../db/schema";
import type { Auth } from "../auth"; import type { Auth } from "../auth";
import type { InferFieldsFromOptions, InferFieldsFromPlugins } from "../db"; import type { InferFieldsFromOptions, InferFieldsFromPlugins } from "../db";
import type { StripEmptyObjects, UnionToIntersection } from "./helper"; import type { StripEmptyObjects, UnionToIntersection } from "./helper";
import type { BetterAuthPlugin } from "./plugins"; import type { BetterAuthPlugin } from "./plugins";
import type * as z from "zod";
import type { User, Session } from "@better-auth/core/db"; import type { User, Session } from "@better-auth/core/db";
export type Models = export type Models =
@@ -85,6 +83,10 @@ interface RateLimit {
lastRequest: number; lastRequest: number;
} }
export type { User, Account, Session } from "@better-auth/core/db"; export type {
export type Verification = z.infer<typeof verificationSchema>; User,
Account,
Session,
Verification,
} from "@better-auth/core/db";
export type { RateLimit }; export type { RateLimit };

View File

@@ -10,6 +10,7 @@ export { coreSchema } from "./schema/shared";
export { userSchema, type User } from "./schema/user"; export { userSchema, type User } from "./schema/user";
export { accountSchema, type Account } from "./schema/account"; export { accountSchema, type Account } from "./schema/account";
export { sessionSchema, type Session } from "./schema/session"; export { sessionSchema, type Session } from "./schema/session";
export { verificationSchema, type Verification } from "./schema/verification";
export type { export type {
DBFieldAttribute, DBFieldAttribute,

View File

@@ -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<typeof verificationSchema>;