@better-auth/core 1.3.26 → 1.3.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,111 +1,96 @@
1
- import { ZodType } from 'zod';
1
+ import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.CnvFgghY.js';
2
+ import * as z from 'zod';
2
3
 
3
- type LiteralString = "" | (string & Record<never, never>);
4
-
5
- type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
6
- type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
7
- type DBFieldAttributeConfig = {
8
- /**
9
- * If the field should be required on a new record.
10
- * @default true
11
- */
12
- required?: boolean;
13
- /**
14
- * If the value should be returned on a response body.
15
- * @default true
16
- */
17
- returned?: boolean;
18
- /**
19
- * If a value should be provided when creating a new record.
20
- * @default true
21
- */
22
- input?: boolean;
23
- /**
24
- * Default value for the field
25
- *
26
- * Note: This will not create a default value on the database level. It will only
27
- * be used when creating a new record.
28
- */
29
- defaultValue?: DBPrimitive | (() => DBPrimitive);
30
- /**
31
- * Update value for the field
32
- *
33
- * Note: This will create an onUpdate trigger on the database level for supported adapters.
34
- * It will be called when updating a record.
35
- */
36
- onUpdate?: () => DBPrimitive;
37
- /**
38
- * transform the value before storing it.
39
- */
40
- transform?: {
41
- input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
42
- output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
43
- };
44
- /**
45
- * Reference to another model.
46
- */
47
- references?: {
48
- /**
49
- * The model to reference.
50
- */
51
- model: string;
52
- /**
53
- * The field on the referenced model.
54
- */
55
- field: string;
56
- /**
57
- * The action to perform when the reference is deleted.
58
- * @default "cascade"
59
- */
60
- onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
61
- };
62
- unique?: boolean;
63
- /**
64
- * If the field should be a bigint on the database instead of integer.
65
- */
66
- bigint?: boolean;
67
- /**
68
- * A zod schema to validate the value.
69
- */
70
- validator?: {
71
- input?: ZodType;
72
- output?: ZodType;
4
+ type BetterAuthPluginDBSchema = {
5
+ [table in string]: {
6
+ fields: {
7
+ [field in string]: DBFieldAttribute;
8
+ };
9
+ disableMigration?: boolean;
10
+ modelName?: string;
73
11
  };
74
- /**
75
- * The name of the field on the database.
76
- */
77
- fieldName?: string;
78
- /**
79
- * If the field should be sortable.
80
- *
81
- * applicable only for `text` type.
82
- * It's useful to mark fields varchar instead of text.
83
- */
84
- sortable?: boolean;
85
12
  };
86
- type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
87
- type: T;
88
- } & DBFieldAttributeConfig;
89
- type BetterAuthDBSchema = Record<string, {
90
- /**
91
- * The name of the table in the database
92
- */
93
- modelName: string;
94
- /**
95
- * The fields of the table
96
- */
97
- fields: Record<string, DBFieldAttribute>;
98
- /**
99
- * Whether to disable migrations for this table
100
- * @default false
101
- */
102
- disableMigrations?: boolean;
103
- /**
104
- * The order of the table
105
- */
106
- order?: number;
107
- }>;
108
13
 
14
+ declare const coreSchema: z.ZodObject<{
15
+ id: z.ZodString;
16
+ createdAt: z.ZodDefault<z.ZodDate>;
17
+ updatedAt: z.ZodDefault<z.ZodDate>;
18
+ }, z.core.$strip>;
19
+
20
+ declare const userSchema: z.ZodObject<{
21
+ id: z.ZodString;
22
+ createdAt: z.ZodDefault<z.ZodDate>;
23
+ updatedAt: z.ZodDefault<z.ZodDate>;
24
+ email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
25
+ emailVerified: z.ZodDefault<z.ZodBoolean>;
26
+ name: z.ZodString;
27
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
+ }, z.core.$strip>;
29
+ /**
30
+ * User schema type used by better-auth, note that it's possible that user could have additional fields
31
+ *
32
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
33
+ */
34
+ type User = z.infer<typeof userSchema>;
35
+
36
+ declare const accountSchema: z.ZodObject<{
37
+ id: z.ZodString;
38
+ createdAt: z.ZodDefault<z.ZodDate>;
39
+ updatedAt: z.ZodDefault<z.ZodDate>;
40
+ providerId: z.ZodString;
41
+ accountId: z.ZodString;
42
+ userId: z.ZodCoercedString<unknown>;
43
+ accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
44
+ refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
+ idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
+ accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
47
+ refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
48
+ scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
49
+ password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
50
+ }, z.core.$strip>;
51
+ /**
52
+ * Account schema type used by better-auth, note that it's possible that account could have additional fields
53
+ *
54
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
55
+ */
56
+ type Account = z.infer<typeof accountSchema>;
57
+
58
+ declare const sessionSchema: z.ZodObject<{
59
+ id: z.ZodString;
60
+ createdAt: z.ZodDefault<z.ZodDate>;
61
+ updatedAt: z.ZodDefault<z.ZodDate>;
62
+ userId: z.ZodCoercedString<unknown>;
63
+ expiresAt: z.ZodDate;
64
+ token: z.ZodString;
65
+ ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
66
+ userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
67
+ }, z.core.$strip>;
68
+ /**
69
+ * Session schema type used by better-auth, note that it's possible that session could have additional fields
70
+ *
71
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
72
+ */
73
+ type Session = z.infer<typeof sessionSchema>;
74
+
75
+ declare const verificationSchema: z.ZodObject<{
76
+ id: z.ZodString;
77
+ createdAt: z.ZodDefault<z.ZodDate>;
78
+ updatedAt: z.ZodDefault<z.ZodDate>;
79
+ value: z.ZodString;
80
+ expiresAt: z.ZodDate;
81
+ identifier: z.ZodString;
82
+ }, z.core.$strip>;
83
+ /**
84
+ * Verification schema type used by better-auth, note that it's possible that verification could have additional fields
85
+ *
86
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
87
+ */
88
+ type Verification = z.infer<typeof verificationSchema>;
89
+
90
+ /**
91
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
92
+ */
93
+ type AuthPluginSchema = BetterAuthPluginDBSchema;
109
94
  /**
110
95
  * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
111
96
  */
@@ -127,4 +112,5 @@ type Primitive = DBPrimitive;
127
112
  */
128
113
  type BetterAuthDbSchema = BetterAuthDBSchema;
129
114
 
130
- export type { BetterAuthDBSchema, BetterAuthDbSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, Primitive };
115
+ export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema };
116
+ export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, Session, User, Verification };
package/dist/db/index.mjs CHANGED
@@ -1 +1,55 @@
1
+ import * as z from 'zod';
1
2
 
3
+ const coreSchema = z.object({
4
+ id: z.string(),
5
+ createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
6
+ updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
7
+ });
8
+
9
+ const userSchema = coreSchema.extend({
10
+ email: z.string().transform((val) => val.toLowerCase()),
11
+ emailVerified: z.boolean().default(false),
12
+ name: z.string(),
13
+ image: z.string().nullish()
14
+ });
15
+
16
+ const accountSchema = coreSchema.extend({
17
+ providerId: z.string(),
18
+ accountId: z.string(),
19
+ userId: z.coerce.string(),
20
+ accessToken: z.string().nullish(),
21
+ refreshToken: z.string().nullish(),
22
+ idToken: z.string().nullish(),
23
+ /**
24
+ * Access token expires at
25
+ */
26
+ accessTokenExpiresAt: z.date().nullish(),
27
+ /**
28
+ * Refresh token expires at
29
+ */
30
+ refreshTokenExpiresAt: z.date().nullish(),
31
+ /**
32
+ * The scopes that the user has authorized
33
+ */
34
+ scope: z.string().nullish(),
35
+ /**
36
+ * Password is only stored in the credential provider
37
+ */
38
+ password: z.string().nullish()
39
+ });
40
+
41
+ const sessionSchema = coreSchema.extend({
42
+ userId: z.coerce.string(),
43
+ expiresAt: z.date(),
44
+ token: z.string(),
45
+ ipAddress: z.string().nullish(),
46
+ userAgent: z.string().nullish()
47
+ });
48
+
49
+ const verificationSchema = coreSchema.extend({
50
+ value: z.string(),
51
+ expiresAt: z.date(),
52
+ identifier: z.string()
53
+ });
54
+
55
+ export { accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema };
package/dist/index.d.cts CHANGED
@@ -1,2 +1,124 @@
1
+ import { L as LiteralUnion, M as Models } from './shared/core.CnvFgghY.cjs';
2
+ export { a as LiteralString } from './shared/core.CnvFgghY.cjs';
3
+ import { CookieOptions } from 'better-call';
4
+ import 'zod';
1
5
 
2
- export { };
6
+ type GenerateIdFn = (options: {
7
+ model: LiteralUnion<Models, string>;
8
+ size?: number;
9
+ }) => string | false;
10
+ type BetterAuthAdvancedOptions = {
11
+ /**
12
+ * Ip address configuration
13
+ */
14
+ ipAddress?: {
15
+ /**
16
+ * List of headers to use for ip address
17
+ *
18
+ * Ip address is used for rate limiting and session tracking
19
+ *
20
+ * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
21
+ *
22
+ * @default
23
+ * @link https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/utils/get-request-ip.ts#L8
24
+ */
25
+ ipAddressHeaders?: string[];
26
+ /**
27
+ * Disable ip tracking
28
+ *
29
+ * ⚠︎ This is a security risk and it may expose your application to abuse
30
+ */
31
+ disableIpTracking?: boolean;
32
+ };
33
+ /**
34
+ * Use secure cookies
35
+ *
36
+ * @default false
37
+ */
38
+ useSecureCookies?: boolean;
39
+ /**
40
+ * Disable trusted origins check
41
+ *
42
+ * ⚠︎ This is a security risk and it may expose your application to CSRF attacks
43
+ */
44
+ disableCSRFCheck?: boolean;
45
+ /**
46
+ * Configure cookies to be cross subdomains
47
+ */
48
+ crossSubDomainCookies?: {
49
+ /**
50
+ * Enable cross subdomain cookies
51
+ */
52
+ enabled: boolean;
53
+ /**
54
+ * Additional cookies to be shared across subdomains
55
+ */
56
+ additionalCookies?: string[];
57
+ /**
58
+ * The domain to use for the cookies
59
+ *
60
+ * By default, the domain will be the root
61
+ * domain from the base URL.
62
+ */
63
+ domain?: string;
64
+ };
65
+ cookies?: {
66
+ [key: string]: {
67
+ name?: string;
68
+ attributes?: CookieOptions;
69
+ };
70
+ };
71
+ defaultCookieAttributes?: CookieOptions;
72
+ /**
73
+ * Prefix for cookies. If a cookie name is provided
74
+ * in cookies config, this will be overridden.
75
+ *
76
+ * @default
77
+ * ```txt
78
+ * "appName" -> which defaults to "better-auth"
79
+ * ```
80
+ */
81
+ cookiePrefix?: string;
82
+ /**
83
+ * Database configuration.
84
+ */
85
+ database?: {
86
+ /**
87
+ * The default number of records to return from the database
88
+ * when using the `findMany` adapter method.
89
+ *
90
+ * @default 100
91
+ */
92
+ defaultFindManyLimit?: number;
93
+ /**
94
+ * If your database auto increments number ids, set this to `true`.
95
+ *
96
+ * Note: If enabled, we will not handle ID generation (including if you use `generateId`), and it would be expected that your database will provide the ID automatically.
97
+ *
98
+ * @default false
99
+ */
100
+ useNumberId?: boolean;
101
+ /**
102
+ * Custom generateId function.
103
+ *
104
+ * If not provided, random ids will be generated.
105
+ * If set to false, the database's auto generated id will be used.
106
+ */
107
+ generateId?: GenerateIdFn | false;
108
+ };
109
+ /**
110
+ * Custom generateId function.
111
+ *
112
+ * If not provided, random ids will be generated.
113
+ * If set to false, the database's auto generated id will be used.
114
+ *
115
+ * @deprecated Please use `database.generateId` instead. This will be potentially removed in future releases.
116
+ */
117
+ generateId?: GenerateIdFn | false;
118
+ };
119
+
120
+ interface BetterAuthMutators<O, C> {
121
+ }
122
+
123
+ export { LiteralUnion };
124
+ export type { BetterAuthAdvancedOptions, BetterAuthMutators, GenerateIdFn };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,124 @@
1
+ import { L as LiteralUnion, M as Models } from './shared/core.CnvFgghY.mjs';
2
+ export { a as LiteralString } from './shared/core.CnvFgghY.mjs';
3
+ import { CookieOptions } from 'better-call';
4
+ import 'zod';
1
5
 
2
- export { };
6
+ type GenerateIdFn = (options: {
7
+ model: LiteralUnion<Models, string>;
8
+ size?: number;
9
+ }) => string | false;
10
+ type BetterAuthAdvancedOptions = {
11
+ /**
12
+ * Ip address configuration
13
+ */
14
+ ipAddress?: {
15
+ /**
16
+ * List of headers to use for ip address
17
+ *
18
+ * Ip address is used for rate limiting and session tracking
19
+ *
20
+ * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
21
+ *
22
+ * @default
23
+ * @link https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/utils/get-request-ip.ts#L8
24
+ */
25
+ ipAddressHeaders?: string[];
26
+ /**
27
+ * Disable ip tracking
28
+ *
29
+ * ⚠︎ This is a security risk and it may expose your application to abuse
30
+ */
31
+ disableIpTracking?: boolean;
32
+ };
33
+ /**
34
+ * Use secure cookies
35
+ *
36
+ * @default false
37
+ */
38
+ useSecureCookies?: boolean;
39
+ /**
40
+ * Disable trusted origins check
41
+ *
42
+ * ⚠︎ This is a security risk and it may expose your application to CSRF attacks
43
+ */
44
+ disableCSRFCheck?: boolean;
45
+ /**
46
+ * Configure cookies to be cross subdomains
47
+ */
48
+ crossSubDomainCookies?: {
49
+ /**
50
+ * Enable cross subdomain cookies
51
+ */
52
+ enabled: boolean;
53
+ /**
54
+ * Additional cookies to be shared across subdomains
55
+ */
56
+ additionalCookies?: string[];
57
+ /**
58
+ * The domain to use for the cookies
59
+ *
60
+ * By default, the domain will be the root
61
+ * domain from the base URL.
62
+ */
63
+ domain?: string;
64
+ };
65
+ cookies?: {
66
+ [key: string]: {
67
+ name?: string;
68
+ attributes?: CookieOptions;
69
+ };
70
+ };
71
+ defaultCookieAttributes?: CookieOptions;
72
+ /**
73
+ * Prefix for cookies. If a cookie name is provided
74
+ * in cookies config, this will be overridden.
75
+ *
76
+ * @default
77
+ * ```txt
78
+ * "appName" -> which defaults to "better-auth"
79
+ * ```
80
+ */
81
+ cookiePrefix?: string;
82
+ /**
83
+ * Database configuration.
84
+ */
85
+ database?: {
86
+ /**
87
+ * The default number of records to return from the database
88
+ * when using the `findMany` adapter method.
89
+ *
90
+ * @default 100
91
+ */
92
+ defaultFindManyLimit?: number;
93
+ /**
94
+ * If your database auto increments number ids, set this to `true`.
95
+ *
96
+ * Note: If enabled, we will not handle ID generation (including if you use `generateId`), and it would be expected that your database will provide the ID automatically.
97
+ *
98
+ * @default false
99
+ */
100
+ useNumberId?: boolean;
101
+ /**
102
+ * Custom generateId function.
103
+ *
104
+ * If not provided, random ids will be generated.
105
+ * If set to false, the database's auto generated id will be used.
106
+ */
107
+ generateId?: GenerateIdFn | false;
108
+ };
109
+ /**
110
+ * Custom generateId function.
111
+ *
112
+ * If not provided, random ids will be generated.
113
+ * If set to false, the database's auto generated id will be used.
114
+ *
115
+ * @deprecated Please use `database.generateId` instead. This will be potentially removed in future releases.
116
+ */
117
+ generateId?: GenerateIdFn | false;
118
+ };
119
+
120
+ interface BetterAuthMutators<O, C> {
121
+ }
122
+
123
+ export { LiteralUnion };
124
+ export type { BetterAuthAdvancedOptions, BetterAuthMutators, GenerateIdFn };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,124 @@
1
+ import { L as LiteralUnion, M as Models } from './shared/core.CnvFgghY.js';
2
+ export { a as LiteralString } from './shared/core.CnvFgghY.js';
3
+ import { CookieOptions } from 'better-call';
4
+ import 'zod';
1
5
 
2
- export { };
6
+ type GenerateIdFn = (options: {
7
+ model: LiteralUnion<Models, string>;
8
+ size?: number;
9
+ }) => string | false;
10
+ type BetterAuthAdvancedOptions = {
11
+ /**
12
+ * Ip address configuration
13
+ */
14
+ ipAddress?: {
15
+ /**
16
+ * List of headers to use for ip address
17
+ *
18
+ * Ip address is used for rate limiting and session tracking
19
+ *
20
+ * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
21
+ *
22
+ * @default
23
+ * @link https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/utils/get-request-ip.ts#L8
24
+ */
25
+ ipAddressHeaders?: string[];
26
+ /**
27
+ * Disable ip tracking
28
+ *
29
+ * ⚠︎ This is a security risk and it may expose your application to abuse
30
+ */
31
+ disableIpTracking?: boolean;
32
+ };
33
+ /**
34
+ * Use secure cookies
35
+ *
36
+ * @default false
37
+ */
38
+ useSecureCookies?: boolean;
39
+ /**
40
+ * Disable trusted origins check
41
+ *
42
+ * ⚠︎ This is a security risk and it may expose your application to CSRF attacks
43
+ */
44
+ disableCSRFCheck?: boolean;
45
+ /**
46
+ * Configure cookies to be cross subdomains
47
+ */
48
+ crossSubDomainCookies?: {
49
+ /**
50
+ * Enable cross subdomain cookies
51
+ */
52
+ enabled: boolean;
53
+ /**
54
+ * Additional cookies to be shared across subdomains
55
+ */
56
+ additionalCookies?: string[];
57
+ /**
58
+ * The domain to use for the cookies
59
+ *
60
+ * By default, the domain will be the root
61
+ * domain from the base URL.
62
+ */
63
+ domain?: string;
64
+ };
65
+ cookies?: {
66
+ [key: string]: {
67
+ name?: string;
68
+ attributes?: CookieOptions;
69
+ };
70
+ };
71
+ defaultCookieAttributes?: CookieOptions;
72
+ /**
73
+ * Prefix for cookies. If a cookie name is provided
74
+ * in cookies config, this will be overridden.
75
+ *
76
+ * @default
77
+ * ```txt
78
+ * "appName" -> which defaults to "better-auth"
79
+ * ```
80
+ */
81
+ cookiePrefix?: string;
82
+ /**
83
+ * Database configuration.
84
+ */
85
+ database?: {
86
+ /**
87
+ * The default number of records to return from the database
88
+ * when using the `findMany` adapter method.
89
+ *
90
+ * @default 100
91
+ */
92
+ defaultFindManyLimit?: number;
93
+ /**
94
+ * If your database auto increments number ids, set this to `true`.
95
+ *
96
+ * Note: If enabled, we will not handle ID generation (including if you use `generateId`), and it would be expected that your database will provide the ID automatically.
97
+ *
98
+ * @default false
99
+ */
100
+ useNumberId?: boolean;
101
+ /**
102
+ * Custom generateId function.
103
+ *
104
+ * If not provided, random ids will be generated.
105
+ * If set to false, the database's auto generated id will be used.
106
+ */
107
+ generateId?: GenerateIdFn | false;
108
+ };
109
+ /**
110
+ * Custom generateId function.
111
+ *
112
+ * If not provided, random ids will be generated.
113
+ * If set to false, the database's auto generated id will be used.
114
+ *
115
+ * @deprecated Please use `database.generateId` instead. This will be potentially removed in future releases.
116
+ */
117
+ generateId?: GenerateIdFn | false;
118
+ };
119
+
120
+ interface BetterAuthMutators<O, C> {
121
+ }
122
+
123
+ export { LiteralUnion };
124
+ export type { BetterAuthAdvancedOptions, BetterAuthMutators, GenerateIdFn };