mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 12:27:44 +00:00
refactor: move account schema to core
This commit is contained in:
@@ -5,31 +5,6 @@ import { APIError } from "better-call";
|
||||
import type { Account, Session, User } from "../types";
|
||||
import { type DBFieldAttribute, coreSchema } from "@better-auth/core/db";
|
||||
|
||||
export const accountSchema = coreSchema.extend({
|
||||
providerId: z.string(),
|
||||
accountId: z.string(),
|
||||
userId: z.coerce.string(),
|
||||
accessToken: z.string().nullish(),
|
||||
refreshToken: z.string().nullish(),
|
||||
idToken: z.string().nullish(),
|
||||
/**
|
||||
* Access token expires at
|
||||
*/
|
||||
accessTokenExpiresAt: z.date().nullish(),
|
||||
/**
|
||||
* Refresh token expires at
|
||||
*/
|
||||
refreshTokenExpiresAt: z.date().nullish(),
|
||||
/**
|
||||
* The scopes that the user has authorized
|
||||
*/
|
||||
scope: z.string().nullish(),
|
||||
/**
|
||||
* Password is only stored in the credential provider
|
||||
*/
|
||||
password: z.string().nullish(),
|
||||
});
|
||||
|
||||
export const sessionSchema = coreSchema.extend({
|
||||
userId: z.coerce.string(),
|
||||
expiresAt: z.date(),
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import type { BetterAuthOptions } from "./options";
|
||||
import type {
|
||||
accountSchema,
|
||||
sessionSchema,
|
||||
verificationSchema,
|
||||
} from "../db/schema";
|
||||
import type { sessionSchema, verificationSchema } from "../db/schema";
|
||||
import type { Auth } from "../auth";
|
||||
import type { InferFieldsFromOptions, InferFieldsFromPlugins } from "../db";
|
||||
import type { StripEmptyObjects, UnionToIntersection } from "./helper";
|
||||
@@ -89,8 +85,7 @@ interface RateLimit {
|
||||
lastRequest: number;
|
||||
}
|
||||
|
||||
export type { User } from "@better-auth/core/db";
|
||||
export type Account = z.infer<typeof accountSchema>;
|
||||
export type { User, Account } from "@better-auth/core/db";
|
||||
export type Session = z.infer<typeof sessionSchema>;
|
||||
export type Verification = z.infer<typeof verificationSchema>;
|
||||
export type { RateLimit };
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
|
||||
export { coreSchema } from "./schema/shared";
|
||||
export { userSchema, type User } from "./schema/user";
|
||||
export { accountSchema, type Account } from "./schema/account";
|
||||
|
||||
export type {
|
||||
DBFieldAttribute,
|
||||
|
||||
34
packages/core/src/db/schema/account.ts
Normal file
34
packages/core/src/db/schema/account.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import * as z from "zod";
|
||||
import { coreSchema } from "./shared";
|
||||
|
||||
export const accountSchema = coreSchema.extend({
|
||||
providerId: z.string(),
|
||||
accountId: z.string(),
|
||||
userId: z.coerce.string(),
|
||||
accessToken: z.string().nullish(),
|
||||
refreshToken: z.string().nullish(),
|
||||
idToken: z.string().nullish(),
|
||||
/**
|
||||
* Access token expires at
|
||||
*/
|
||||
accessTokenExpiresAt: z.date().nullish(),
|
||||
/**
|
||||
* Refresh token expires at
|
||||
*/
|
||||
refreshTokenExpiresAt: z.date().nullish(),
|
||||
/**
|
||||
* The scopes that the user has authorized
|
||||
*/
|
||||
scope: z.string().nullish(),
|
||||
/**
|
||||
* Password is only stored in the credential provider
|
||||
*/
|
||||
password: z.string().nullish(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Account schema type used by better-auth, note that it's possible that account 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 Account = z.infer<typeof accountSchema>;
|
||||
Reference in New Issue
Block a user