@better-auth/core 1.4.0-beta.6 → 1.4.0-beta.7
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.
- package/.turbo/turbo-build.log +14 -9
- package/build.config.ts +6 -1
- package/dist/async_hooks/index.cjs +27 -0
- package/dist/async_hooks/index.d.cts +10 -0
- package/dist/async_hooks/index.d.mts +10 -0
- package/dist/async_hooks/index.d.ts +10 -0
- package/dist/async_hooks/index.mjs +25 -0
- package/dist/db/adapter/index.cjs +2 -0
- package/dist/db/adapter/index.d.cts +23 -0
- package/dist/db/adapter/index.d.mts +23 -0
- package/dist/db/adapter/index.d.ts +23 -0
- package/dist/db/adapter/index.mjs +1 -0
- package/dist/db/index.cjs +73 -0
- package/dist/db/index.d.cts +91 -105
- package/dist/db/index.d.mts +91 -105
- package/dist/db/index.d.ts +91 -105
- package/dist/db/index.mjs +54 -0
- package/dist/index.d.cts +114 -1
- package/dist/index.d.mts +114 -1
- package/dist/index.d.ts +114 -1
- package/dist/shared/core.CnvFgghY.d.cts +117 -0
- package/dist/shared/core.CnvFgghY.d.mts +117 -0
- package/dist/shared/core.CnvFgghY.d.ts +117 -0
- package/package.json +24 -1
- package/src/async_hooks/index.ts +43 -0
- package/src/db/adapter/index.ts +24 -0
- package/src/db/index.ts +11 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +34 -0
- package/src/db/schema/session.ts +17 -0
- package/src/db/schema/shared.ts +7 -0
- package/src/db/schema/user.ts +16 -0
- package/src/db/schema/verification.ts +15 -0
- package/src/db/type.ts +22 -0
- package/src/index.ts +3 -1
- package/src/types/helper.ts +5 -0
- package/src/types/index.ts +2 -1
- package/src/types/init-options.ts +119 -0
- package/tsconfig.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,115 @@
|
|
|
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
|
-
|
|
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
|
+
|
|
111
|
+
interface BetterAuthMutators<O, C> {
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { LiteralUnion };
|
|
115
|
+
export type { BetterAuthAdvancedOptions, BetterAuthMutators, GenerateIdFn };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
|
|
3
|
+
type Primitive = string | number | symbol | bigint | boolean | null | undefined;
|
|
4
|
+
type LiteralString = "" | (string & Record<never, never>);
|
|
5
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
6
|
+
|
|
7
|
+
declare module "../index" {
|
|
8
|
+
interface BetterAuthMutators<O, C> {
|
|
9
|
+
"better-auth/db": {};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
type Models = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
|
|
13
|
+
type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
|
|
14
|
+
type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
|
|
15
|
+
type DBFieldAttributeConfig = {
|
|
16
|
+
/**
|
|
17
|
+
* If the field should be required on a new record.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
required?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If the value should be returned on a response body.
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
returned?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* If a value should be provided when creating a new record.
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
input?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Default value for the field
|
|
33
|
+
*
|
|
34
|
+
* Note: This will not create a default value on the database level. It will only
|
|
35
|
+
* be used when creating a new record.
|
|
36
|
+
*/
|
|
37
|
+
defaultValue?: DBPrimitive | (() => DBPrimitive);
|
|
38
|
+
/**
|
|
39
|
+
* Update value for the field
|
|
40
|
+
*
|
|
41
|
+
* Note: This will create an onUpdate trigger on the database level for supported adapters.
|
|
42
|
+
* It will be called when updating a record.
|
|
43
|
+
*/
|
|
44
|
+
onUpdate?: () => DBPrimitive;
|
|
45
|
+
/**
|
|
46
|
+
* transform the value before storing it.
|
|
47
|
+
*/
|
|
48
|
+
transform?: {
|
|
49
|
+
input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
50
|
+
output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Reference to another model.
|
|
54
|
+
*/
|
|
55
|
+
references?: {
|
|
56
|
+
/**
|
|
57
|
+
* The model to reference.
|
|
58
|
+
*/
|
|
59
|
+
model: string;
|
|
60
|
+
/**
|
|
61
|
+
* The field on the referenced model.
|
|
62
|
+
*/
|
|
63
|
+
field: string;
|
|
64
|
+
/**
|
|
65
|
+
* The action to perform when the reference is deleted.
|
|
66
|
+
* @default "cascade"
|
|
67
|
+
*/
|
|
68
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
69
|
+
};
|
|
70
|
+
unique?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* If the field should be a bigint on the database instead of integer.
|
|
73
|
+
*/
|
|
74
|
+
bigint?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* A zod schema to validate the value.
|
|
77
|
+
*/
|
|
78
|
+
validator?: {
|
|
79
|
+
input?: ZodType;
|
|
80
|
+
output?: ZodType;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The name of the field on the database.
|
|
84
|
+
*/
|
|
85
|
+
fieldName?: string;
|
|
86
|
+
/**
|
|
87
|
+
* If the field should be sortable.
|
|
88
|
+
*
|
|
89
|
+
* applicable only for `text` type.
|
|
90
|
+
* It's useful to mark fields varchar instead of text.
|
|
91
|
+
*/
|
|
92
|
+
sortable?: boolean;
|
|
93
|
+
};
|
|
94
|
+
type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
|
|
95
|
+
type: T;
|
|
96
|
+
} & DBFieldAttributeConfig;
|
|
97
|
+
type BetterAuthDBSchema = Record<string, {
|
|
98
|
+
/**
|
|
99
|
+
* The name of the table in the database
|
|
100
|
+
*/
|
|
101
|
+
modelName: string;
|
|
102
|
+
/**
|
|
103
|
+
* The fields of the table
|
|
104
|
+
*/
|
|
105
|
+
fields: Record<string, DBFieldAttribute>;
|
|
106
|
+
/**
|
|
107
|
+
* Whether to disable migrations for this table
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
disableMigrations?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* The order of the table
|
|
113
|
+
*/
|
|
114
|
+
order?: number;
|
|
115
|
+
}>;
|
|
116
|
+
|
|
117
|
+
export type { BetterAuthDBSchema as B, DBFieldAttribute as D, LiteralUnion as L, Models as M, LiteralString as a, DBFieldAttributeConfig as b, DBFieldType as c, DBPrimitive as d };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
|
|
3
|
+
type Primitive = string | number | symbol | bigint | boolean | null | undefined;
|
|
4
|
+
type LiteralString = "" | (string & Record<never, never>);
|
|
5
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
6
|
+
|
|
7
|
+
declare module "../index" {
|
|
8
|
+
interface BetterAuthMutators<O, C> {
|
|
9
|
+
"better-auth/db": {};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
type Models = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
|
|
13
|
+
type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
|
|
14
|
+
type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
|
|
15
|
+
type DBFieldAttributeConfig = {
|
|
16
|
+
/**
|
|
17
|
+
* If the field should be required on a new record.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
required?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If the value should be returned on a response body.
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
returned?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* If a value should be provided when creating a new record.
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
input?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Default value for the field
|
|
33
|
+
*
|
|
34
|
+
* Note: This will not create a default value on the database level. It will only
|
|
35
|
+
* be used when creating a new record.
|
|
36
|
+
*/
|
|
37
|
+
defaultValue?: DBPrimitive | (() => DBPrimitive);
|
|
38
|
+
/**
|
|
39
|
+
* Update value for the field
|
|
40
|
+
*
|
|
41
|
+
* Note: This will create an onUpdate trigger on the database level for supported adapters.
|
|
42
|
+
* It will be called when updating a record.
|
|
43
|
+
*/
|
|
44
|
+
onUpdate?: () => DBPrimitive;
|
|
45
|
+
/**
|
|
46
|
+
* transform the value before storing it.
|
|
47
|
+
*/
|
|
48
|
+
transform?: {
|
|
49
|
+
input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
50
|
+
output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Reference to another model.
|
|
54
|
+
*/
|
|
55
|
+
references?: {
|
|
56
|
+
/**
|
|
57
|
+
* The model to reference.
|
|
58
|
+
*/
|
|
59
|
+
model: string;
|
|
60
|
+
/**
|
|
61
|
+
* The field on the referenced model.
|
|
62
|
+
*/
|
|
63
|
+
field: string;
|
|
64
|
+
/**
|
|
65
|
+
* The action to perform when the reference is deleted.
|
|
66
|
+
* @default "cascade"
|
|
67
|
+
*/
|
|
68
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
69
|
+
};
|
|
70
|
+
unique?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* If the field should be a bigint on the database instead of integer.
|
|
73
|
+
*/
|
|
74
|
+
bigint?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* A zod schema to validate the value.
|
|
77
|
+
*/
|
|
78
|
+
validator?: {
|
|
79
|
+
input?: ZodType;
|
|
80
|
+
output?: ZodType;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The name of the field on the database.
|
|
84
|
+
*/
|
|
85
|
+
fieldName?: string;
|
|
86
|
+
/**
|
|
87
|
+
* If the field should be sortable.
|
|
88
|
+
*
|
|
89
|
+
* applicable only for `text` type.
|
|
90
|
+
* It's useful to mark fields varchar instead of text.
|
|
91
|
+
*/
|
|
92
|
+
sortable?: boolean;
|
|
93
|
+
};
|
|
94
|
+
type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
|
|
95
|
+
type: T;
|
|
96
|
+
} & DBFieldAttributeConfig;
|
|
97
|
+
type BetterAuthDBSchema = Record<string, {
|
|
98
|
+
/**
|
|
99
|
+
* The name of the table in the database
|
|
100
|
+
*/
|
|
101
|
+
modelName: string;
|
|
102
|
+
/**
|
|
103
|
+
* The fields of the table
|
|
104
|
+
*/
|
|
105
|
+
fields: Record<string, DBFieldAttribute>;
|
|
106
|
+
/**
|
|
107
|
+
* Whether to disable migrations for this table
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
disableMigrations?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* The order of the table
|
|
113
|
+
*/
|
|
114
|
+
order?: number;
|
|
115
|
+
}>;
|
|
116
|
+
|
|
117
|
+
export type { BetterAuthDBSchema as B, DBFieldAttribute as D, LiteralUnion as L, Models as M, LiteralString as a, DBFieldAttributeConfig as b, DBFieldType as c, DBPrimitive as d };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
|
|
3
|
+
type Primitive = string | number | symbol | bigint | boolean | null | undefined;
|
|
4
|
+
type LiteralString = "" | (string & Record<never, never>);
|
|
5
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
6
|
+
|
|
7
|
+
declare module "../index" {
|
|
8
|
+
interface BetterAuthMutators<O, C> {
|
|
9
|
+
"better-auth/db": {};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
type Models = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
|
|
13
|
+
type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
|
|
14
|
+
type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
|
|
15
|
+
type DBFieldAttributeConfig = {
|
|
16
|
+
/**
|
|
17
|
+
* If the field should be required on a new record.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
required?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If the value should be returned on a response body.
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
returned?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* If a value should be provided when creating a new record.
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
input?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Default value for the field
|
|
33
|
+
*
|
|
34
|
+
* Note: This will not create a default value on the database level. It will only
|
|
35
|
+
* be used when creating a new record.
|
|
36
|
+
*/
|
|
37
|
+
defaultValue?: DBPrimitive | (() => DBPrimitive);
|
|
38
|
+
/**
|
|
39
|
+
* Update value for the field
|
|
40
|
+
*
|
|
41
|
+
* Note: This will create an onUpdate trigger on the database level for supported adapters.
|
|
42
|
+
* It will be called when updating a record.
|
|
43
|
+
*/
|
|
44
|
+
onUpdate?: () => DBPrimitive;
|
|
45
|
+
/**
|
|
46
|
+
* transform the value before storing it.
|
|
47
|
+
*/
|
|
48
|
+
transform?: {
|
|
49
|
+
input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
50
|
+
output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Reference to another model.
|
|
54
|
+
*/
|
|
55
|
+
references?: {
|
|
56
|
+
/**
|
|
57
|
+
* The model to reference.
|
|
58
|
+
*/
|
|
59
|
+
model: string;
|
|
60
|
+
/**
|
|
61
|
+
* The field on the referenced model.
|
|
62
|
+
*/
|
|
63
|
+
field: string;
|
|
64
|
+
/**
|
|
65
|
+
* The action to perform when the reference is deleted.
|
|
66
|
+
* @default "cascade"
|
|
67
|
+
*/
|
|
68
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
69
|
+
};
|
|
70
|
+
unique?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* If the field should be a bigint on the database instead of integer.
|
|
73
|
+
*/
|
|
74
|
+
bigint?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* A zod schema to validate the value.
|
|
77
|
+
*/
|
|
78
|
+
validator?: {
|
|
79
|
+
input?: ZodType;
|
|
80
|
+
output?: ZodType;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The name of the field on the database.
|
|
84
|
+
*/
|
|
85
|
+
fieldName?: string;
|
|
86
|
+
/**
|
|
87
|
+
* If the field should be sortable.
|
|
88
|
+
*
|
|
89
|
+
* applicable only for `text` type.
|
|
90
|
+
* It's useful to mark fields varchar instead of text.
|
|
91
|
+
*/
|
|
92
|
+
sortable?: boolean;
|
|
93
|
+
};
|
|
94
|
+
type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
|
|
95
|
+
type: T;
|
|
96
|
+
} & DBFieldAttributeConfig;
|
|
97
|
+
type BetterAuthDBSchema = Record<string, {
|
|
98
|
+
/**
|
|
99
|
+
* The name of the table in the database
|
|
100
|
+
*/
|
|
101
|
+
modelName: string;
|
|
102
|
+
/**
|
|
103
|
+
* The fields of the table
|
|
104
|
+
*/
|
|
105
|
+
fields: Record<string, DBFieldAttribute>;
|
|
106
|
+
/**
|
|
107
|
+
* Whether to disable migrations for this table
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
disableMigrations?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* The order of the table
|
|
113
|
+
*/
|
|
114
|
+
order?: number;
|
|
115
|
+
}>;
|
|
116
|
+
|
|
117
|
+
export type { BetterAuthDBSchema as B, DBFieldAttribute as D, LiteralUnion as L, Models as M, LiteralString as a, DBFieldAttributeConfig as b, DBFieldType as c, DBPrimitive as d };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/core",
|
|
3
|
-
"version": "1.4.0-beta.
|
|
3
|
+
"version": "1.4.0-beta.7",
|
|
4
4
|
"description": "The most comprehensive authentication library for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -16,6 +16,16 @@
|
|
|
16
16
|
"default": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"./async_hooks": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/async_hooks/index.d.ts",
|
|
22
|
+
"default": "./dist/async_hooks/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/async_hooks/index.d.cts",
|
|
26
|
+
"default": "./dist/async_hooks/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
19
29
|
"./db": {
|
|
20
30
|
"import": {
|
|
21
31
|
"types": "./dist/db/index.d.ts",
|
|
@@ -25,6 +35,16 @@
|
|
|
25
35
|
"types": "./dist/db/index.d.cts",
|
|
26
36
|
"default": "./dist/db/index.cjs"
|
|
27
37
|
}
|
|
38
|
+
},
|
|
39
|
+
"./db/adapter": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/db/adapter/index.d.ts",
|
|
42
|
+
"default": "./dist/db/adapter/index.mjs"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/db/adapter/index.d.cts",
|
|
46
|
+
"default": "./dist/db/adapter/index.cjs"
|
|
47
|
+
}
|
|
28
48
|
}
|
|
29
49
|
},
|
|
30
50
|
"typesVersions": {
|
|
@@ -32,6 +52,9 @@
|
|
|
32
52
|
"index": [
|
|
33
53
|
"dist/index.d.ts"
|
|
34
54
|
],
|
|
55
|
+
"async_hooks": [
|
|
56
|
+
"dist/async_hooks.d.ts"
|
|
57
|
+
],
|
|
35
58
|
"db": [
|
|
36
59
|
"dist/db.d.ts"
|
|
37
60
|
]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncLocalStorage will be import directly in 1.5.x
|
|
3
|
+
*/
|
|
4
|
+
import type { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
|
|
6
|
+
// We only export the type here to avoid issues in environments where AsyncLocalStorage is not available.
|
|
7
|
+
export type { AsyncLocalStorage };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Dynamically import AsyncLocalStorage to avoid issues in environments where it's not available.
|
|
11
|
+
*
|
|
12
|
+
* Right now, this is primarily for Cloudflare Workers.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
let moduleName: string = "node:async_hooks";
|
|
16
|
+
|
|
17
|
+
const AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage> = import(
|
|
18
|
+
/* @vite-ignore */
|
|
19
|
+
/* webpackIgnore: true */
|
|
20
|
+
moduleName
|
|
21
|
+
)
|
|
22
|
+
.then((mod) => mod.AsyncLocalStorage)
|
|
23
|
+
.catch((err) => {
|
|
24
|
+
if ("AsyncLocalStorage" in globalThis) {
|
|
25
|
+
return (globalThis as any).AsyncLocalStorage;
|
|
26
|
+
}
|
|
27
|
+
console.warn(
|
|
28
|
+
"[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.",
|
|
29
|
+
);
|
|
30
|
+
console.warn(
|
|
31
|
+
"[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler",
|
|
32
|
+
);
|
|
33
|
+
console.warn(
|
|
34
|
+
"[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag",
|
|
35
|
+
);
|
|
36
|
+
throw err;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export async function getAsyncLocalStorage(): Promise<
|
|
40
|
+
typeof AsyncLocalStorage
|
|
41
|
+
> {
|
|
42
|
+
return AsyncLocalStoragePromise;
|
|
43
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type DBAdapterDebugLogOption =
|
|
2
|
+
| boolean
|
|
3
|
+
| {
|
|
4
|
+
/**
|
|
5
|
+
* Useful when you want to log only certain conditions.
|
|
6
|
+
*/
|
|
7
|
+
logCondition?: (() => boolean) | undefined;
|
|
8
|
+
create?: boolean;
|
|
9
|
+
update?: boolean;
|
|
10
|
+
updateMany?: boolean;
|
|
11
|
+
findOne?: boolean;
|
|
12
|
+
findMany?: boolean;
|
|
13
|
+
delete?: boolean;
|
|
14
|
+
deleteMany?: boolean;
|
|
15
|
+
count?: boolean;
|
|
16
|
+
}
|
|
17
|
+
| {
|
|
18
|
+
/**
|
|
19
|
+
* Only used for adapter tests to show debug logs if a test fails.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
|
|
22
|
+
*/
|
|
23
|
+
isRunningAdapterTests: boolean;
|
|
24
|
+
};
|
package/src/db/index.ts
CHANGED
|
@@ -5,6 +5,13 @@ import type {
|
|
|
5
5
|
DBPrimitive,
|
|
6
6
|
BetterAuthDBSchema,
|
|
7
7
|
} from "./type";
|
|
8
|
+
import type { BetterAuthPluginDBSchema } from "./plugin";
|
|
9
|
+
export type { BetterAuthPluginDBSchema } from "./plugin";
|
|
10
|
+
export { coreSchema } from "./schema/shared";
|
|
11
|
+
export { userSchema, type User } from "./schema/user";
|
|
12
|
+
export { accountSchema, type Account } from "./schema/account";
|
|
13
|
+
export { sessionSchema, type Session } from "./schema/session";
|
|
14
|
+
export { verificationSchema, type Verification } from "./schema/verification";
|
|
8
15
|
|
|
9
16
|
export type {
|
|
10
17
|
DBFieldAttribute,
|
|
@@ -14,6 +21,10 @@ export type {
|
|
|
14
21
|
BetterAuthDBSchema,
|
|
15
22
|
};
|
|
16
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
26
|
+
*/
|
|
27
|
+
export type AuthPluginSchema = BetterAuthPluginDBSchema;
|
|
17
28
|
/**
|
|
18
29
|
* @deprecated Backport for 1.3.x, we will remove this in 1.4.x
|
|
19
30
|
*/
|
package/src/db/plugin.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { coreSchema } from "./shared";
|
|
3
|
+
|
|
4
|
+
export const accountSchema = coreSchema.extend({
|
|
5
|
+
providerId: z.string(),
|
|
6
|
+
accountId: z.string(),
|
|
7
|
+
userId: z.coerce.string(),
|
|
8
|
+
accessToken: z.string().nullish(),
|
|
9
|
+
refreshToken: z.string().nullish(),
|
|
10
|
+
idToken: z.string().nullish(),
|
|
11
|
+
/**
|
|
12
|
+
* Access token expires at
|
|
13
|
+
*/
|
|
14
|
+
accessTokenExpiresAt: z.date().nullish(),
|
|
15
|
+
/**
|
|
16
|
+
* Refresh token expires at
|
|
17
|
+
*/
|
|
18
|
+
refreshTokenExpiresAt: z.date().nullish(),
|
|
19
|
+
/**
|
|
20
|
+
* The scopes that the user has authorized
|
|
21
|
+
*/
|
|
22
|
+
scope: z.string().nullish(),
|
|
23
|
+
/**
|
|
24
|
+
* Password is only stored in the credential provider
|
|
25
|
+
*/
|
|
26
|
+
password: z.string().nullish(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Account schema type used by better-auth, note that it's possible that account 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
|
+
export type Account = z.infer<typeof accountSchema>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { coreSchema } from "./shared";
|
|
3
|
+
|
|
4
|
+
export const sessionSchema = coreSchema.extend({
|
|
5
|
+
userId: z.coerce.string(),
|
|
6
|
+
expiresAt: z.date(),
|
|
7
|
+
token: z.string(),
|
|
8
|
+
ipAddress: z.string().nullish(),
|
|
9
|
+
userAgent: z.string().nullish(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Session schema type used by better-auth, note that it's possible that session could have additional fields
|
|
14
|
+
*
|
|
15
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
16
|
+
*/
|
|
17
|
+
export type Session = z.infer<typeof sessionSchema>;
|