mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 12:27:44 +00:00
refactor: move verification schema to core
This commit is contained in:
@@ -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<
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
15
packages/core/src/db/schema/verification.ts
Normal file
15
packages/core/src/db/schema/verification.ts
Normal 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>;
|
||||||
Reference in New Issue
Block a user