@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.
- package/.turbo/turbo-build.log +10 -9
- package/build.config.ts +1 -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 +123 -1
- package/dist/index.d.mts +123 -1
- package/dist/index.d.ts +123 -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 +11 -1
- 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 +128 -0
|
@@ -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.3.
|
|
3
|
+
"version": "1.3.27",
|
|
4
4
|
"description": "The most comprehensive authentication library for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -35,6 +35,16 @@
|
|
|
35
35
|
"types": "./dist/db/index.d.cts",
|
|
36
36
|
"default": "./dist/db/index.cjs"
|
|
37
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
|
+
}
|
|
38
48
|
}
|
|
39
49
|
},
|
|
40
50
|
"typesVersions": {
|
|
@@ -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>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { coreSchema } from "./shared";
|
|
3
|
+
|
|
4
|
+
export const userSchema = coreSchema.extend({
|
|
5
|
+
email: z.string().transform((val) => val.toLowerCase()),
|
|
6
|
+
emailVerified: z.boolean().default(false),
|
|
7
|
+
name: z.string(),
|
|
8
|
+
image: z.string().nullish(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* User schema type used by better-auth, note that it's possible that user could have additional fields
|
|
13
|
+
*
|
|
14
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
15
|
+
*/
|
|
16
|
+
export type User = z.infer<typeof userSchema>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { coreSchema } from "./shared";
|
|
3
|
+
|
|
4
|
+
export const verificationSchema = coreSchema.extend({
|
|
5
|
+
value: z.string(),
|
|
6
|
+
expiresAt: z.date(),
|
|
7
|
+
identifier: z.string(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Verification schema type used by better-auth, note that it's possible that verification could have additional fields
|
|
12
|
+
*
|
|
13
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
14
|
+
*/
|
|
15
|
+
export type Verification = z.infer<typeof verificationSchema>;
|
package/src/db/type.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import type { ZodType } from "zod";
|
|
2
2
|
import type { LiteralString } from "../types";
|
|
3
3
|
|
|
4
|
+
declare module "../index" {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
interface BetterAuthMutators<O, C> {
|
|
7
|
+
"better-auth/db": {
|
|
8
|
+
// todo: we should infer the schema from the adapter
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type Models =
|
|
14
|
+
| "user"
|
|
15
|
+
| "account"
|
|
16
|
+
| "session"
|
|
17
|
+
| "verification"
|
|
18
|
+
| "rate-limit"
|
|
19
|
+
| "organization"
|
|
20
|
+
| "member"
|
|
21
|
+
| "invitation"
|
|
22
|
+
| "jwks"
|
|
23
|
+
| "passkey"
|
|
24
|
+
| "two-factor";
|
|
25
|
+
|
|
4
26
|
export type DBFieldType =
|
|
5
27
|
| "string"
|
|
6
28
|
| "number"
|
package/src/index.ts
CHANGED
package/src/types/helper.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
+
type Primitive = string | number | symbol | bigint | boolean | null | undefined;
|
|
2
|
+
|
|
1
3
|
export type LiteralString = "" | (string & Record<never, never>);
|
|
4
|
+
export type LiteralUnion<LiteralType, BaseType extends Primitive> =
|
|
5
|
+
| LiteralType
|
|
6
|
+
| (BaseType & Record<never, never>);
|
package/src/types/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./helper";
|
|
1
|
+
export type * from "./helper";
|
|
2
|
+
export type { BetterAuthAdvancedOptions, GenerateIdFn } from "./init-options";
|