@depup/better-auth__core 1.6.23-depup.2
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/LICENSE.md +20 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/api/index.d.mts +281 -0
- package/dist/api/index.mjs +92 -0
- package/dist/async_hooks/index.d.mts +6 -0
- package/dist/async_hooks/index.mjs +20 -0
- package/dist/async_hooks/pure.index.d.mts +6 -0
- package/dist/async_hooks/pure.index.mjs +33 -0
- package/dist/context/endpoint-context.d.mts +18 -0
- package/dist/context/endpoint-context.mjs +29 -0
- package/dist/context/global.d.mts +6 -0
- package/dist/context/global.mjs +36 -0
- package/dist/context/index.d.mts +5 -0
- package/dist/context/index.mjs +5 -0
- package/dist/context/request-state.d.mts +27 -0
- package/dist/context/request-state.mjs +47 -0
- package/dist/context/transaction.d.mts +27 -0
- package/dist/context/transaction.mjs +96 -0
- package/dist/db/adapter/factory.d.mts +17 -0
- package/dist/db/adapter/factory.mjs +905 -0
- package/dist/db/adapter/get-default-field-name.d.mts +18 -0
- package/dist/db/adapter/get-default-field-name.mjs +36 -0
- package/dist/db/adapter/get-default-model-name.d.mts +12 -0
- package/dist/db/adapter/get-default-model-name.mjs +30 -0
- package/dist/db/adapter/get-field-attributes.d.mts +26 -0
- package/dist/db/adapter/get-field-attributes.mjs +37 -0
- package/dist/db/adapter/get-field-name.d.mts +18 -0
- package/dist/db/adapter/get-field-name.mjs +31 -0
- package/dist/db/adapter/get-id-field.d.mts +36 -0
- package/dist/db/adapter/get-id-field.mjs +64 -0
- package/dist/db/adapter/get-model-name.d.mts +12 -0
- package/dist/db/adapter/get-model-name.mjs +21 -0
- package/dist/db/adapter/index.d.mts +615 -0
- package/dist/db/adapter/index.mjs +24 -0
- package/dist/db/adapter/types.d.mts +105 -0
- package/dist/db/adapter/utils.d.mts +7 -0
- package/dist/db/adapter/utils.mjs +37 -0
- package/dist/db/get-tables.d.mts +6 -0
- package/dist/db/get-tables.mjs +266 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +8 -0
- package/dist/db/plugin.d.mts +12 -0
- package/dist/db/schema/account.d.mts +28 -0
- package/dist/db/schema/account.mjs +17 -0
- package/dist/db/schema/rate-limit.d.mts +18 -0
- package/dist/db/schema/rate-limit.mjs +9 -0
- package/dist/db/schema/session.d.mts +23 -0
- package/dist/db/schema/session.mjs +12 -0
- package/dist/db/schema/shared.d.mts +10 -0
- package/dist/db/schema/shared.mjs +9 -0
- package/dist/db/schema/user.d.mts +22 -0
- package/dist/db/schema/user.mjs +11 -0
- package/dist/db/schema/verification.d.mts +21 -0
- package/dist/db/schema/verification.mjs +10 -0
- package/dist/db/type.d.mts +194 -0
- package/dist/env/color-depth.d.mts +4 -0
- package/dist/env/color-depth.mjs +86 -0
- package/dist/env/env-impl.d.mts +32 -0
- package/dist/env/env-impl.mjs +81 -0
- package/dist/env/index.d.mts +4 -0
- package/dist/env/index.mjs +4 -0
- package/dist/env/logger.d.mts +48 -0
- package/dist/env/logger.mjs +79 -0
- package/dist/error/codes.d.mts +69 -0
- package/dist/error/codes.mjs +55 -0
- package/dist/error/index.d.mts +26 -0
- package/dist/error/index.mjs +27 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +1 -0
- package/dist/instrumentation/api.mjs +12 -0
- package/dist/instrumentation/attributes.d.mts +11 -0
- package/dist/instrumentation/attributes.mjs +10 -0
- package/dist/instrumentation/index.d.mts +3 -0
- package/dist/instrumentation/index.mjs +3 -0
- package/dist/instrumentation/noop.mjs +42 -0
- package/dist/instrumentation/pure.index.d.mts +7 -0
- package/dist/instrumentation/pure.index.mjs +7 -0
- package/dist/instrumentation/tracer.d.mts +13 -0
- package/dist/instrumentation/tracer.mjs +53 -0
- package/dist/oauth2/client-credentials-token.d.mts +56 -0
- package/dist/oauth2/client-credentials-token.mjs +64 -0
- package/dist/oauth2/create-authorization-url.d.mts +44 -0
- package/dist/oauth2/create-authorization-url.mjs +41 -0
- package/dist/oauth2/index.d.mts +8 -0
- package/dist/oauth2/index.mjs +7 -0
- package/dist/oauth2/oauth-provider.d.mts +192 -0
- package/dist/oauth2/refresh-access-token.d.mts +54 -0
- package/dist/oauth2/refresh-access-token.mjs +73 -0
- package/dist/oauth2/reject-redirects.mjs +60 -0
- package/dist/oauth2/utils.d.mts +24 -0
- package/dist/oauth2/utils.mjs +48 -0
- package/dist/oauth2/validate-authorization-code.d.mts +85 -0
- package/dist/oauth2/validate-authorization-code.mjs +86 -0
- package/dist/oauth2/verify.d.mts +65 -0
- package/dist/oauth2/verify.mjs +202 -0
- package/dist/social-providers/apple.d.mts +133 -0
- package/dist/social-providers/apple.mjs +117 -0
- package/dist/social-providers/atlassian.d.mts +70 -0
- package/dist/social-providers/atlassian.mjs +80 -0
- package/dist/social-providers/cognito.d.mts +85 -0
- package/dist/social-providers/cognito.mjs +162 -0
- package/dist/social-providers/discord.d.mts +124 -0
- package/dist/social-providers/discord.mjs +62 -0
- package/dist/social-providers/dropbox.d.mts +69 -0
- package/dist/social-providers/dropbox.mjs +72 -0
- package/dist/social-providers/facebook.d.mts +79 -0
- package/dist/social-providers/facebook.mjs +157 -0
- package/dist/social-providers/figma.d.mts +61 -0
- package/dist/social-providers/figma.mjs +83 -0
- package/dist/social-providers/github.d.mts +102 -0
- package/dist/social-providers/github.mjs +92 -0
- package/dist/social-providers/gitlab.d.mts +123 -0
- package/dist/social-providers/gitlab.mjs +79 -0
- package/dist/social-providers/google.d.mts +123 -0
- package/dist/social-providers/google.mjs +137 -0
- package/dist/social-providers/huggingface.d.mts +83 -0
- package/dist/social-providers/huggingface.mjs +73 -0
- package/dist/social-providers/index.d.mts +1834 -0
- package/dist/social-providers/index.mjs +78 -0
- package/dist/social-providers/kakao.d.mts +161 -0
- package/dist/social-providers/kakao.mjs +70 -0
- package/dist/social-providers/kick.d.mts +73 -0
- package/dist/social-providers/kick.mjs +68 -0
- package/dist/social-providers/line.d.mts +105 -0
- package/dist/social-providers/line.mjs +110 -0
- package/dist/social-providers/linear.d.mts +68 -0
- package/dist/social-providers/linear.mjs +85 -0
- package/dist/social-providers/linkedin.d.mts +67 -0
- package/dist/social-providers/linkedin.mjs +73 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
- package/dist/social-providers/microsoft-entra-id.mjs +152 -0
- package/dist/social-providers/naver.d.mts +92 -0
- package/dist/social-providers/naver.mjs +65 -0
- package/dist/social-providers/notion.d.mts +64 -0
- package/dist/social-providers/notion.mjs +72 -0
- package/dist/social-providers/paybin.d.mts +71 -0
- package/dist/social-providers/paybin.mjs +81 -0
- package/dist/social-providers/paypal.d.mts +131 -0
- package/dist/social-providers/paypal.mjs +188 -0
- package/dist/social-providers/polar.d.mts +74 -0
- package/dist/social-providers/polar.mjs +71 -0
- package/dist/social-providers/railway.d.mts +65 -0
- package/dist/social-providers/railway.mjs +74 -0
- package/dist/social-providers/reddit.d.mts +62 -0
- package/dist/social-providers/reddit.mjs +81 -0
- package/dist/social-providers/roblox.d.mts +70 -0
- package/dist/social-providers/roblox.mjs +57 -0
- package/dist/social-providers/salesforce.d.mts +79 -0
- package/dist/social-providers/salesforce.mjs +87 -0
- package/dist/social-providers/slack.d.mts +83 -0
- package/dist/social-providers/slack.mjs +66 -0
- package/dist/social-providers/spotify.d.mts +63 -0
- package/dist/social-providers/spotify.mjs +69 -0
- package/dist/social-providers/tiktok.d.mts +168 -0
- package/dist/social-providers/tiktok.mjs +60 -0
- package/dist/social-providers/twitch.d.mts +79 -0
- package/dist/social-providers/twitch.mjs +75 -0
- package/dist/social-providers/twitter.d.mts +126 -0
- package/dist/social-providers/twitter.mjs +85 -0
- package/dist/social-providers/vercel.d.mts +62 -0
- package/dist/social-providers/vercel.mjs +58 -0
- package/dist/social-providers/vk.d.mts +70 -0
- package/dist/social-providers/vk.mjs +81 -0
- package/dist/social-providers/wechat.d.mts +113 -0
- package/dist/social-providers/wechat.mjs +81 -0
- package/dist/social-providers/zoom.d.mts +163 -0
- package/dist/social-providers/zoom.mjs +69 -0
- package/dist/types/context.d.mts +319 -0
- package/dist/types/cookie.d.mts +15 -0
- package/dist/types/helper.d.mts +10 -0
- package/dist/types/index.d.mts +9 -0
- package/dist/types/init-options.d.mts +1430 -0
- package/dist/types/plugin-client.d.mts +123 -0
- package/dist/types/plugin.d.mts +124 -0
- package/dist/types/secret.d.mts +11 -0
- package/dist/utils/async.d.mts +22 -0
- package/dist/utils/async.mjs +32 -0
- package/dist/utils/db.d.mts +9 -0
- package/dist/utils/db.mjs +15 -0
- package/dist/utils/deprecate.d.mts +9 -0
- package/dist/utils/deprecate.mjs +16 -0
- package/dist/utils/error-codes.d.mts +13 -0
- package/dist/utils/error-codes.mjs +10 -0
- package/dist/utils/fetch-metadata.d.mts +4 -0
- package/dist/utils/fetch-metadata.mjs +6 -0
- package/dist/utils/host.d.mts +147 -0
- package/dist/utils/host.mjs +295 -0
- package/dist/utils/id.d.mts +4 -0
- package/dist/utils/id.mjs +7 -0
- package/dist/utils/ip.d.mts +77 -0
- package/dist/utils/ip.mjs +230 -0
- package/dist/utils/is-api-error.d.mts +6 -0
- package/dist/utils/is-api-error.mjs +8 -0
- package/dist/utils/json.d.mts +4 -0
- package/dist/utils/json.mjs +41 -0
- package/dist/utils/redirect-uri.d.mts +20 -0
- package/dist/utils/redirect-uri.mjs +48 -0
- package/dist/utils/string.d.mts +8 -0
- package/dist/utils/string.mjs +25 -0
- package/dist/utils/url.d.mts +37 -0
- package/dist/utils/url.mjs +61 -0
- package/package.json +216 -0
- package/src/api/index.ts +185 -0
- package/src/async_hooks/index.ts +40 -0
- package/src/async_hooks/pure.index.ts +46 -0
- package/src/context/endpoint-context.ts +50 -0
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +23 -0
- package/src/context/request-state.ts +91 -0
- package/src/context/transaction.ts +169 -0
- package/src/db/adapter/factory.ts +1740 -0
- package/src/db/adapter/get-default-field-name.ts +59 -0
- package/src/db/adapter/get-default-model-name.ts +51 -0
- package/src/db/adapter/get-field-attributes.ts +62 -0
- package/src/db/adapter/get-field-name.ts +43 -0
- package/src/db/adapter/get-id-field.ts +150 -0
- package/src/db/adapter/get-model-name.ts +36 -0
- package/src/db/adapter/index.ts +656 -0
- package/src/db/adapter/types.ts +134 -0
- package/src/db/adapter/utils.ts +61 -0
- package/src/db/get-tables.ts +304 -0
- package/src/db/index.ts +43 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +47 -0
- package/src/db/schema/rate-limit.ts +36 -0
- package/src/db/schema/session.ts +29 -0
- package/src/db/schema/shared.ts +7 -0
- package/src/db/schema/user.ts +31 -0
- package/src/db/schema/verification.ts +28 -0
- package/src/db/type.ts +360 -0
- package/src/env/color-depth.ts +172 -0
- package/src/env/env-impl.ts +123 -0
- package/src/env/index.ts +23 -0
- package/src/env/logger.ts +145 -0
- package/src/error/codes.ts +72 -0
- package/src/error/index.ts +44 -0
- package/src/index.ts +1 -0
- package/src/instrumentation/api.ts +17 -0
- package/src/instrumentation/attributes.ts +22 -0
- package/src/instrumentation/index.ts +2 -0
- package/src/instrumentation/noop.ts +74 -0
- package/src/instrumentation/pure.index.ts +31 -0
- package/src/instrumentation/tracer.ts +95 -0
- package/src/oauth2/client-credentials-token.ts +126 -0
- package/src/oauth2/create-authorization-url.ts +89 -0
- package/src/oauth2/index.ts +34 -0
- package/src/oauth2/oauth-provider.ts +222 -0
- package/src/oauth2/refresh-access-token.ts +157 -0
- package/src/oauth2/reject-redirects.ts +70 -0
- package/src/oauth2/utils.ts +70 -0
- package/src/oauth2/validate-authorization-code.ts +190 -0
- package/src/oauth2/verify.ts +408 -0
- package/src/social-providers/apple.ts +249 -0
- package/src/social-providers/atlassian.ts +133 -0
- package/src/social-providers/cognito.ts +281 -0
- package/src/social-providers/discord.ts +170 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +288 -0
- package/src/social-providers/figma.ts +118 -0
- package/src/social-providers/github.ts +184 -0
- package/src/social-providers/gitlab.ts +155 -0
- package/src/social-providers/google.ts +263 -0
- package/src/social-providers/huggingface.ts +119 -0
- package/src/social-providers/index.ts +132 -0
- package/src/social-providers/kakao.ts +179 -0
- package/src/social-providers/kick.ts +109 -0
- package/src/social-providers/line.ts +169 -0
- package/src/social-providers/linear.ts +121 -0
- package/src/social-providers/linkedin.ts +110 -0
- package/src/social-providers/microsoft-entra-id.ts +391 -0
- package/src/social-providers/naver.ts +113 -0
- package/src/social-providers/notion.ts +108 -0
- package/src/social-providers/paybin.ts +118 -0
- package/src/social-providers/paypal.ts +371 -0
- package/src/social-providers/polar.ts +111 -0
- package/src/social-providers/railway.ts +100 -0
- package/src/social-providers/reddit.ts +126 -0
- package/src/social-providers/roblox.ts +112 -0
- package/src/social-providers/salesforce.ts +159 -0
- package/src/social-providers/slack.ts +112 -0
- package/src/social-providers/spotify.ts +94 -0
- package/src/social-providers/tiktok.ts +211 -0
- package/src/social-providers/twitch.ts +112 -0
- package/src/social-providers/twitter.ts +199 -0
- package/src/social-providers/vercel.ts +87 -0
- package/src/social-providers/vk.ts +125 -0
- package/src/social-providers/wechat.ts +220 -0
- package/src/social-providers/zoom.ts +230 -0
- package/src/types/context.ts +460 -0
- package/src/types/cookie.ts +10 -0
- package/src/types/helper.ts +27 -0
- package/src/types/index.ts +40 -0
- package/src/types/init-options.ts +1679 -0
- package/src/types/plugin-client.ts +143 -0
- package/src/types/plugin.ts +163 -0
- package/src/types/secret.ts +8 -0
- package/src/utils/async.ts +53 -0
- package/src/utils/db.ts +20 -0
- package/src/utils/deprecate.ts +21 -0
- package/src/utils/error-codes.ts +68 -0
- package/src/utils/fetch-metadata.ts +3 -0
- package/src/utils/host.ts +416 -0
- package/src/utils/id.ts +5 -0
- package/src/utils/ip.ts +395 -0
- package/src/utils/is-api-error.ts +10 -0
- package/src/utils/json.ts +56 -0
- package/src/utils/redirect-uri.ts +54 -0
- package/src/utils/string.ts +40 -0
- package/src/utils/url.ts +77 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
import { CleanedWhere, CustomAdapter, DBAdapterFactoryConfig, DBTransactionAdapter, JoinConfig, Where } from "./index.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
//#region src/db/adapter/types.d.ts
|
|
5
|
+
type AdapterFactoryOptions = {
|
|
6
|
+
config: AdapterFactoryConfig;
|
|
7
|
+
adapter: AdapterFactoryCustomizeAdapterCreator;
|
|
8
|
+
};
|
|
9
|
+
interface AdapterFactoryConfig extends Omit<DBAdapterFactoryConfig<BetterAuthOptions>, "transaction"> {
|
|
10
|
+
/**
|
|
11
|
+
* Execute multiple operations in a transaction.
|
|
12
|
+
*
|
|
13
|
+
* If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
|
|
14
|
+
*
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
transaction?: (false | (<R>(callback: (trx: DBTransactionAdapter) => Promise<R>) => Promise<R>)) | undefined;
|
|
18
|
+
}
|
|
19
|
+
type AdapterFactoryCustomizeAdapterCreator = (config: {
|
|
20
|
+
options: BetterAuthOptions;
|
|
21
|
+
/**
|
|
22
|
+
* The schema of the user's Better-Auth instance.
|
|
23
|
+
*/
|
|
24
|
+
schema: BetterAuthDBSchema;
|
|
25
|
+
/**
|
|
26
|
+
* The debug log function.
|
|
27
|
+
*
|
|
28
|
+
* If the config has defined `debugLogs` as `false`, no logs will be shown.
|
|
29
|
+
*/
|
|
30
|
+
debugLog: (...args: unknown[]) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Get the model name which is expected to be saved in the database based on the user's schema.
|
|
33
|
+
*/
|
|
34
|
+
getModelName: (model: string) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
37
|
+
*/
|
|
38
|
+
getFieldName: ({
|
|
39
|
+
model,
|
|
40
|
+
field
|
|
41
|
+
}: {
|
|
42
|
+
model: string;
|
|
43
|
+
field: string;
|
|
44
|
+
}) => string;
|
|
45
|
+
/**
|
|
46
|
+
* This function helps us get the default model name from the schema defined by devs.
|
|
47
|
+
* Often times, the user will be using the `modelName` which could had been customized by the users.
|
|
48
|
+
* This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
|
|
49
|
+
*
|
|
50
|
+
* If it's still unclear what this does:
|
|
51
|
+
*
|
|
52
|
+
* 1. User can define a custom modelName.
|
|
53
|
+
* 2. When using a custom modelName, doing something like `schema[model]` will not work.
|
|
54
|
+
* 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
|
|
55
|
+
* 4. Thus allowing us to use `schema[model]`.
|
|
56
|
+
*/
|
|
57
|
+
getDefaultModelName: (model: string) => string;
|
|
58
|
+
/**
|
|
59
|
+
* This function helps us get the default field name from the schema defined by devs.
|
|
60
|
+
* Often times, the user will be using the `fieldName` which could had been customized by the users.
|
|
61
|
+
* This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
|
|
62
|
+
*
|
|
63
|
+
* If it's still unclear what this does:
|
|
64
|
+
*
|
|
65
|
+
* 1. User can define a custom fieldName.
|
|
66
|
+
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
getDefaultFieldName: ({
|
|
70
|
+
model,
|
|
71
|
+
field
|
|
72
|
+
}: {
|
|
73
|
+
model: string;
|
|
74
|
+
field: string;
|
|
75
|
+
}) => string;
|
|
76
|
+
/**
|
|
77
|
+
* Get the field attributes for a given model and field.
|
|
78
|
+
*
|
|
79
|
+
* Note: any model name or field name is allowed, whether default to schema or not.
|
|
80
|
+
*/
|
|
81
|
+
getFieldAttributes: ({
|
|
82
|
+
model,
|
|
83
|
+
field
|
|
84
|
+
}: {
|
|
85
|
+
model: string;
|
|
86
|
+
field: string;
|
|
87
|
+
}) => DBFieldAttribute;
|
|
88
|
+
transformInput: (data: Record<string, unknown>, defaultModelName: string, action: "create" | "update", forceAllowId?: boolean | undefined) => Promise<Record<string, unknown>>;
|
|
89
|
+
transformOutput: (data: Record<string, unknown>, defaultModelName: string, select?: string[] | undefined, joinConfig?: JoinConfig | undefined) => Promise<Record<string, unknown>>;
|
|
90
|
+
transformWhereClause: <W extends Where[] | undefined>({
|
|
91
|
+
model,
|
|
92
|
+
where,
|
|
93
|
+
action
|
|
94
|
+
}: {
|
|
95
|
+
where: W;
|
|
96
|
+
model: string;
|
|
97
|
+
action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "consumeOne" | "incrementOne" | "count";
|
|
98
|
+
}) => W extends undefined ? undefined : CleanedWhere[];
|
|
99
|
+
}) => CustomAdapter;
|
|
100
|
+
type AdapterTestDebugLogs = {
|
|
101
|
+
resetDebugLogs: () => void;
|
|
102
|
+
printDebugLogs: () => void;
|
|
103
|
+
};
|
|
104
|
+
//#endregion
|
|
105
|
+
export { AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/db/adapter/utils.d.ts
|
|
4
|
+
declare function withApplyDefault(value: any, field: DBFieldAttribute, action: "create" | "update" | "findOne" | "findMany"): any;
|
|
5
|
+
declare function deepmerge<T>(target: T, source: Partial<T>): T;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { deepmerge, withApplyDefault };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/db/adapter/utils.ts
|
|
2
|
+
function withApplyDefault(value, field, action) {
|
|
3
|
+
if (action === "update") {
|
|
4
|
+
if (value === void 0 && field.onUpdate !== void 0) {
|
|
5
|
+
if (typeof field.onUpdate === "function") return field.onUpdate();
|
|
6
|
+
return field.onUpdate;
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
if (action === "create") {
|
|
11
|
+
if (value === void 0 || field.required === true && value === null) {
|
|
12
|
+
if (field.defaultValue !== void 0) {
|
|
13
|
+
if (typeof field.defaultValue === "function") return field.defaultValue();
|
|
14
|
+
return field.defaultValue;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function isObject(item) {
|
|
21
|
+
return item !== null && typeof item === "object" && !Array.isArray(item);
|
|
22
|
+
}
|
|
23
|
+
function deepmerge(target, source) {
|
|
24
|
+
if (Array.isArray(target) && Array.isArray(source)) return [...target, ...source];
|
|
25
|
+
else if (isObject(target) && isObject(source)) {
|
|
26
|
+
const result = { ...target };
|
|
27
|
+
for (const [key, value] of Object.entries(source)) {
|
|
28
|
+
if (value === void 0) continue;
|
|
29
|
+
if (key in target) result[key] = deepmerge(target[key], value);
|
|
30
|
+
else result[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
return source;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { deepmerge, withApplyDefault };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BetterAuthDBSchema } from "./type.mjs";
|
|
2
|
+
import { BetterAuthOptions } from "../types/init-options.mjs";
|
|
3
|
+
//#region src/db/get-tables.d.ts
|
|
4
|
+
declare const getAuthTables: (options: BetterAuthOptions) => BetterAuthDBSchema;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getAuthTables };
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
//#region src/db/get-tables.ts
|
|
2
|
+
const getAuthTables = (options) => {
|
|
3
|
+
const pluginSchema = (options.plugins ?? []).reduce((acc, plugin) => {
|
|
4
|
+
const schema = plugin.schema;
|
|
5
|
+
if (!schema) return acc;
|
|
6
|
+
for (const [key, value] of Object.entries(schema)) acc[key] = {
|
|
7
|
+
fields: {
|
|
8
|
+
...acc[key]?.fields,
|
|
9
|
+
...value.fields
|
|
10
|
+
},
|
|
11
|
+
modelName: value.modelName || key,
|
|
12
|
+
disableMigrations: value.disableMigration ?? acc[key]?.disableMigrations
|
|
13
|
+
};
|
|
14
|
+
return acc;
|
|
15
|
+
}, {});
|
|
16
|
+
const shouldAddRateLimitTable = options.rateLimit?.storage === "database";
|
|
17
|
+
const rateLimitTable = { rateLimit: {
|
|
18
|
+
modelName: options.rateLimit?.modelName || "rateLimit",
|
|
19
|
+
fields: {
|
|
20
|
+
key: {
|
|
21
|
+
type: "string",
|
|
22
|
+
unique: true,
|
|
23
|
+
required: true,
|
|
24
|
+
fieldName: options.rateLimit?.fields?.key || "key"
|
|
25
|
+
},
|
|
26
|
+
count: {
|
|
27
|
+
type: "number",
|
|
28
|
+
required: true,
|
|
29
|
+
fieldName: options.rateLimit?.fields?.count || "count"
|
|
30
|
+
},
|
|
31
|
+
lastRequest: {
|
|
32
|
+
type: "number",
|
|
33
|
+
bigint: true,
|
|
34
|
+
required: true,
|
|
35
|
+
fieldName: options.rateLimit?.fields?.lastRequest || "lastRequest",
|
|
36
|
+
defaultValue: () => Date.now()
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} };
|
|
40
|
+
const { user, session, account, verification, ...pluginTables } = pluginSchema;
|
|
41
|
+
const verificationTable = { verification: {
|
|
42
|
+
modelName: options.verification?.modelName || "verification",
|
|
43
|
+
fields: {
|
|
44
|
+
identifier: {
|
|
45
|
+
type: "string",
|
|
46
|
+
required: true,
|
|
47
|
+
fieldName: options.verification?.fields?.identifier || "identifier",
|
|
48
|
+
index: true
|
|
49
|
+
},
|
|
50
|
+
value: {
|
|
51
|
+
type: "string",
|
|
52
|
+
required: true,
|
|
53
|
+
fieldName: options.verification?.fields?.value || "value"
|
|
54
|
+
},
|
|
55
|
+
expiresAt: {
|
|
56
|
+
type: "date",
|
|
57
|
+
required: true,
|
|
58
|
+
fieldName: options.verification?.fields?.expiresAt || "expiresAt"
|
|
59
|
+
},
|
|
60
|
+
createdAt: {
|
|
61
|
+
type: "date",
|
|
62
|
+
required: true,
|
|
63
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
64
|
+
fieldName: options.verification?.fields?.createdAt || "createdAt"
|
|
65
|
+
},
|
|
66
|
+
updatedAt: {
|
|
67
|
+
type: "date",
|
|
68
|
+
required: true,
|
|
69
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
70
|
+
onUpdate: () => /* @__PURE__ */ new Date(),
|
|
71
|
+
fieldName: options.verification?.fields?.updatedAt || "updatedAt"
|
|
72
|
+
},
|
|
73
|
+
...verification?.fields,
|
|
74
|
+
...options.verification?.additionalFields
|
|
75
|
+
},
|
|
76
|
+
order: 4
|
|
77
|
+
} };
|
|
78
|
+
const sessionTable = { session: {
|
|
79
|
+
modelName: options.session?.modelName || "session",
|
|
80
|
+
fields: {
|
|
81
|
+
expiresAt: {
|
|
82
|
+
type: "date",
|
|
83
|
+
required: true,
|
|
84
|
+
fieldName: options.session?.fields?.expiresAt || "expiresAt"
|
|
85
|
+
},
|
|
86
|
+
token: {
|
|
87
|
+
type: "string",
|
|
88
|
+
required: true,
|
|
89
|
+
fieldName: options.session?.fields?.token || "token",
|
|
90
|
+
unique: true
|
|
91
|
+
},
|
|
92
|
+
createdAt: {
|
|
93
|
+
type: "date",
|
|
94
|
+
required: true,
|
|
95
|
+
fieldName: options.session?.fields?.createdAt || "createdAt",
|
|
96
|
+
defaultValue: () => /* @__PURE__ */ new Date()
|
|
97
|
+
},
|
|
98
|
+
updatedAt: {
|
|
99
|
+
type: "date",
|
|
100
|
+
required: true,
|
|
101
|
+
fieldName: options.session?.fields?.updatedAt || "updatedAt",
|
|
102
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
103
|
+
},
|
|
104
|
+
ipAddress: {
|
|
105
|
+
type: "string",
|
|
106
|
+
required: false,
|
|
107
|
+
fieldName: options.session?.fields?.ipAddress || "ipAddress"
|
|
108
|
+
},
|
|
109
|
+
userAgent: {
|
|
110
|
+
type: "string",
|
|
111
|
+
required: false,
|
|
112
|
+
fieldName: options.session?.fields?.userAgent || "userAgent"
|
|
113
|
+
},
|
|
114
|
+
userId: {
|
|
115
|
+
type: "string",
|
|
116
|
+
fieldName: options.session?.fields?.userId || "userId",
|
|
117
|
+
references: {
|
|
118
|
+
model: options.user?.modelName || "user",
|
|
119
|
+
field: "id",
|
|
120
|
+
onDelete: "cascade"
|
|
121
|
+
},
|
|
122
|
+
required: true,
|
|
123
|
+
index: true
|
|
124
|
+
},
|
|
125
|
+
...session?.fields,
|
|
126
|
+
...options.session?.additionalFields
|
|
127
|
+
},
|
|
128
|
+
order: 2
|
|
129
|
+
} };
|
|
130
|
+
return {
|
|
131
|
+
user: {
|
|
132
|
+
modelName: options.user?.modelName || "user",
|
|
133
|
+
fields: {
|
|
134
|
+
name: {
|
|
135
|
+
type: "string",
|
|
136
|
+
required: true,
|
|
137
|
+
fieldName: options.user?.fields?.name || "name",
|
|
138
|
+
sortable: true
|
|
139
|
+
},
|
|
140
|
+
email: {
|
|
141
|
+
type: "string",
|
|
142
|
+
unique: true,
|
|
143
|
+
required: true,
|
|
144
|
+
fieldName: options.user?.fields?.email || "email",
|
|
145
|
+
sortable: true
|
|
146
|
+
},
|
|
147
|
+
emailVerified: {
|
|
148
|
+
type: "boolean",
|
|
149
|
+
defaultValue: false,
|
|
150
|
+
required: true,
|
|
151
|
+
fieldName: options.user?.fields?.emailVerified || "emailVerified",
|
|
152
|
+
input: false
|
|
153
|
+
},
|
|
154
|
+
image: {
|
|
155
|
+
type: "string",
|
|
156
|
+
required: false,
|
|
157
|
+
fieldName: options.user?.fields?.image || "image"
|
|
158
|
+
},
|
|
159
|
+
createdAt: {
|
|
160
|
+
type: "date",
|
|
161
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
162
|
+
required: true,
|
|
163
|
+
fieldName: options.user?.fields?.createdAt || "createdAt"
|
|
164
|
+
},
|
|
165
|
+
updatedAt: {
|
|
166
|
+
type: "date",
|
|
167
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
168
|
+
onUpdate: () => /* @__PURE__ */ new Date(),
|
|
169
|
+
required: true,
|
|
170
|
+
fieldName: options.user?.fields?.updatedAt || "updatedAt"
|
|
171
|
+
},
|
|
172
|
+
...user?.fields,
|
|
173
|
+
...options.user?.additionalFields
|
|
174
|
+
},
|
|
175
|
+
order: 1
|
|
176
|
+
},
|
|
177
|
+
...!options.secondaryStorage || options.session?.storeSessionInDatabase ? sessionTable : {},
|
|
178
|
+
account: {
|
|
179
|
+
modelName: options.account?.modelName || "account",
|
|
180
|
+
fields: {
|
|
181
|
+
accountId: {
|
|
182
|
+
type: "string",
|
|
183
|
+
required: true,
|
|
184
|
+
fieldName: options.account?.fields?.accountId || "accountId"
|
|
185
|
+
},
|
|
186
|
+
providerId: {
|
|
187
|
+
type: "string",
|
|
188
|
+
required: true,
|
|
189
|
+
fieldName: options.account?.fields?.providerId || "providerId"
|
|
190
|
+
},
|
|
191
|
+
userId: {
|
|
192
|
+
type: "string",
|
|
193
|
+
references: {
|
|
194
|
+
model: options.user?.modelName || "user",
|
|
195
|
+
field: "id",
|
|
196
|
+
onDelete: "cascade"
|
|
197
|
+
},
|
|
198
|
+
required: true,
|
|
199
|
+
fieldName: options.account?.fields?.userId || "userId",
|
|
200
|
+
index: true
|
|
201
|
+
},
|
|
202
|
+
accessToken: {
|
|
203
|
+
type: "string",
|
|
204
|
+
required: false,
|
|
205
|
+
returned: false,
|
|
206
|
+
fieldName: options.account?.fields?.accessToken || "accessToken"
|
|
207
|
+
},
|
|
208
|
+
refreshToken: {
|
|
209
|
+
type: "string",
|
|
210
|
+
required: false,
|
|
211
|
+
returned: false,
|
|
212
|
+
fieldName: options.account?.fields?.refreshToken || "refreshToken"
|
|
213
|
+
},
|
|
214
|
+
idToken: {
|
|
215
|
+
type: "string",
|
|
216
|
+
required: false,
|
|
217
|
+
returned: false,
|
|
218
|
+
fieldName: options.account?.fields?.idToken || "idToken"
|
|
219
|
+
},
|
|
220
|
+
accessTokenExpiresAt: {
|
|
221
|
+
type: "date",
|
|
222
|
+
required: false,
|
|
223
|
+
returned: false,
|
|
224
|
+
fieldName: options.account?.fields?.accessTokenExpiresAt || "accessTokenExpiresAt"
|
|
225
|
+
},
|
|
226
|
+
refreshTokenExpiresAt: {
|
|
227
|
+
type: "date",
|
|
228
|
+
required: false,
|
|
229
|
+
returned: false,
|
|
230
|
+
fieldName: options.account?.fields?.refreshTokenExpiresAt || "refreshTokenExpiresAt"
|
|
231
|
+
},
|
|
232
|
+
scope: {
|
|
233
|
+
type: "string",
|
|
234
|
+
required: false,
|
|
235
|
+
fieldName: options.account?.fields?.scope || "scope"
|
|
236
|
+
},
|
|
237
|
+
password: {
|
|
238
|
+
type: "string",
|
|
239
|
+
required: false,
|
|
240
|
+
returned: false,
|
|
241
|
+
fieldName: options.account?.fields?.password || "password"
|
|
242
|
+
},
|
|
243
|
+
createdAt: {
|
|
244
|
+
type: "date",
|
|
245
|
+
required: true,
|
|
246
|
+
fieldName: options.account?.fields?.createdAt || "createdAt",
|
|
247
|
+
defaultValue: () => /* @__PURE__ */ new Date()
|
|
248
|
+
},
|
|
249
|
+
updatedAt: {
|
|
250
|
+
type: "date",
|
|
251
|
+
required: true,
|
|
252
|
+
fieldName: options.account?.fields?.updatedAt || "updatedAt",
|
|
253
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
254
|
+
},
|
|
255
|
+
...account?.fields,
|
|
256
|
+
...options.account?.additionalFields
|
|
257
|
+
},
|
|
258
|
+
order: 3
|
|
259
|
+
},
|
|
260
|
+
...!options.secondaryStorage || options.verification?.storeInDatabase ? verificationTable : {},
|
|
261
|
+
...pluginTables,
|
|
262
|
+
...shouldAddRateLimitTable ? rateLimitTable : {}
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
//#endregion
|
|
266
|
+
export { getAuthTables };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseModelNames, BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, InferDBFieldInput, InferDBFieldOutput, InferDBFieldsFromOptions, InferDBFieldsFromOptionsInput, InferDBFieldsFromPlugins, InferDBFieldsFromPluginsInput, InferDBFieldsInput, InferDBFieldsOutput, InferDBValueType, ModelNames, SecondaryStorage } from "./type.mjs";
|
|
2
|
+
import { getAuthTables } from "./get-tables.mjs";
|
|
3
|
+
import { BetterAuthPluginDBSchema } from "./plugin.mjs";
|
|
4
|
+
import { BaseRateLimit, RateLimit, rateLimitSchema } from "./schema/rate-limit.mjs";
|
|
5
|
+
import { BaseSession, Session, sessionSchema } from "./schema/session.mjs";
|
|
6
|
+
import { BaseUser, User, userSchema } from "./schema/user.mjs";
|
|
7
|
+
import { BaseVerification, Verification, verificationSchema } from "./schema/verification.mjs";
|
|
8
|
+
import { Account, BaseAccount, accountSchema } from "./schema/account.mjs";
|
|
9
|
+
import { coreSchema } from "./schema/shared.mjs";
|
|
10
|
+
export { type Account, type BaseAccount, type BaseModelNames, type BaseRateLimit, type BaseSession, type BaseUser, type BaseVerification, type BetterAuthDBSchema, type BetterAuthPluginDBSchema, type DBFieldAttribute, type DBFieldAttributeConfig, type DBFieldType, type DBPrimitive, type InferDBFieldInput, type InferDBFieldOutput, type InferDBFieldsFromOptions, type InferDBFieldsFromOptionsInput, type InferDBFieldsFromPlugins, type InferDBFieldsFromPluginsInput, type InferDBFieldsInput, type InferDBFieldsOutput, type InferDBValueType, type ModelNames, type RateLimit, type SecondaryStorage, type Session, type User, type Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getAuthTables } from "./get-tables.mjs";
|
|
2
|
+
import { coreSchema } from "./schema/shared.mjs";
|
|
3
|
+
import { accountSchema } from "./schema/account.mjs";
|
|
4
|
+
import { rateLimitSchema } from "./schema/rate-limit.mjs";
|
|
5
|
+
import { sessionSchema } from "./schema/session.mjs";
|
|
6
|
+
import { userSchema } from "./schema/user.mjs";
|
|
7
|
+
import { verificationSchema } from "./schema/verification.mjs";
|
|
8
|
+
export { accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DBFieldAttribute } from "./type.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/db/plugin.d.ts
|
|
4
|
+
type BetterAuthPluginDBSchema = { [table in string]: {
|
|
5
|
+
fields: {
|
|
6
|
+
[field: string]: DBFieldAttribute;
|
|
7
|
+
};
|
|
8
|
+
disableMigration?: boolean | undefined;
|
|
9
|
+
modelName?: string | undefined;
|
|
10
|
+
} };
|
|
11
|
+
//#endregion
|
|
12
|
+
export { BetterAuthPluginDBSchema };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/db/schema/account.d.ts
|
|
7
|
+
declare const accountSchema: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
10
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
11
|
+
providerId: z.ZodString;
|
|
12
|
+
accountId: z.ZodString;
|
|
13
|
+
userId: z.ZodCoercedString<unknown>;
|
|
14
|
+
accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
15
|
+
refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
|
+
idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
18
|
+
refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
19
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
type BaseAccount = z.infer<typeof accountSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* Account schema type used by better-auth, note that it's possible that account could have additional fields
|
|
25
|
+
*/
|
|
26
|
+
type Account<DBOptions extends BetterAuthOptions["account"] = BetterAuthOptions["account"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify<BaseAccount & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"account", Plugins>>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { Account, BaseAccount, accountSchema };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//#region src/db/schema/account.ts
|
|
4
|
+
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
|
+
accessTokenExpiresAt: z.date().nullish(),
|
|
12
|
+
refreshTokenExpiresAt: z.date().nullish(),
|
|
13
|
+
scope: z.string().nullish(),
|
|
14
|
+
password: z.string().nullish()
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { accountSchema };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/db/schema/rate-limit.d.ts
|
|
7
|
+
declare const rateLimitSchema: z.ZodObject<{
|
|
8
|
+
key: z.ZodString;
|
|
9
|
+
count: z.ZodNumber;
|
|
10
|
+
lastRequest: z.ZodNumber;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
type BaseRateLimit = z.infer<typeof rateLimitSchema>;
|
|
13
|
+
/**
|
|
14
|
+
* Rate limit schema type used by better-auth for rate limiting
|
|
15
|
+
*/
|
|
16
|
+
type RateLimit<DBOptions extends BetterAuthOptions["rateLimit"] = BetterAuthOptions["rateLimit"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify<BaseRateLimit & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"rateLimit", Plugins>>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { BaseRateLimit, RateLimit, rateLimitSchema };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/db/schema/session.d.ts
|
|
7
|
+
declare const sessionSchema: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
10
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
11
|
+
userId: z.ZodCoercedString<unknown>;
|
|
12
|
+
expiresAt: z.ZodDate;
|
|
13
|
+
token: z.ZodString;
|
|
14
|
+
ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
15
|
+
userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
type BaseSession = z.infer<typeof sessionSchema>;
|
|
18
|
+
/**
|
|
19
|
+
* Session schema type used by better-auth, note that it's possible that session could have additional fields
|
|
20
|
+
*/
|
|
21
|
+
type Session<DBOptions extends BetterAuthOptions["session"] = BetterAuthOptions["session"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify<z.infer<typeof sessionSchema> & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"session", Plugins>>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { BaseSession, Session, sessionSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//#region src/db/schema/session.ts
|
|
4
|
+
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
|
+
//#endregion
|
|
12
|
+
export { sessionSchema };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/shared.d.ts
|
|
4
|
+
declare const coreSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { coreSchema };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
//#region src/db/schema/shared.ts
|
|
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
|
+
//#endregion
|
|
9
|
+
export { coreSchema };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/db/schema/user.d.ts
|
|
7
|
+
declare const userSchema: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
10
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
11
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
12
|
+
emailVerified: z.ZodDefault<z.ZodBoolean>;
|
|
13
|
+
name: z.ZodString;
|
|
14
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
type BaseUser = z.infer<typeof userSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* User schema type used by better-auth, note that it's possible that user could have additional fields
|
|
19
|
+
*/
|
|
20
|
+
type User<DBOptions extends BetterAuthOptions["user"] = BetterAuthOptions["user"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify<BaseUser & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"user", Plugins>>;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { BaseUser, User, userSchema };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//#region src/db/schema/user.ts
|
|
4
|
+
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
|
+
//#endregion
|
|
11
|
+
export { userSchema };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/db/schema/verification.d.ts
|
|
7
|
+
declare const verificationSchema: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
10
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
11
|
+
value: z.ZodString;
|
|
12
|
+
expiresAt: z.ZodDate;
|
|
13
|
+
identifier: z.ZodString;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
type BaseVerification = z.infer<typeof verificationSchema>;
|
|
16
|
+
/**
|
|
17
|
+
* Verification schema type used by better-auth, note that it's possible that verification could have additional fields
|
|
18
|
+
*/
|
|
19
|
+
type Verification<DBOptions extends BetterAuthOptions["verification"] = BetterAuthOptions["verification"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify<BaseVerification & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"verification", Plugins>>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { BaseVerification, Verification, verificationSchema };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//#region src/db/schema/verification.ts
|
|
4
|
+
const verificationSchema = coreSchema.extend({
|
|
5
|
+
value: z.string(),
|
|
6
|
+
expiresAt: z.date(),
|
|
7
|
+
identifier: z.string()
|
|
8
|
+
});
|
|
9
|
+
//#endregion
|
|
10
|
+
export { verificationSchema };
|