@better-auth/core 1.3.26 → 1.3.28
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 +60 -9
- package/build.config.ts +7 -0
- package/dist/db/adapter/index.cjs +2 -0
- package/dist/db/adapter/index.d.cts +14 -0
- package/dist/db/adapter/index.d.mts +14 -0
- package/dist/db/adapter/index.d.ts +14 -0
- package/dist/db/adapter/index.mjs +1 -0
- package/dist/db/index.cjs +89 -0
- package/dist/db/index.d.cts +16 -107
- package/dist/db/index.d.mts +16 -107
- package/dist/db/index.d.ts +16 -107
- package/dist/db/index.mjs +69 -0
- package/dist/env/index.cjs +312 -0
- package/dist/env/index.d.cts +36 -0
- package/dist/env/index.d.mts +36 -0
- package/dist/env/index.d.ts +36 -0
- package/dist/env/index.mjs +297 -0
- package/dist/error/index.cjs +44 -0
- package/dist/error/index.d.cts +33 -0
- package/dist/error/index.d.mts +33 -0
- package/dist/error/index.d.ts +33 -0
- package/dist/error/index.mjs +41 -0
- package/dist/index.d.cts +179 -1
- package/dist/index.d.mts +179 -1
- package/dist/index.d.ts +179 -1
- package/dist/middleware/index.cjs +25 -0
- package/dist/middleware/index.d.cts +14 -0
- package/dist/middleware/index.d.mts +14 -0
- package/dist/middleware/index.d.ts +14 -0
- package/dist/middleware/index.mjs +21 -0
- package/dist/oauth2/index.cjs +368 -0
- package/dist/oauth2/index.d.cts +100 -0
- package/dist/oauth2/index.d.mts +100 -0
- package/dist/oauth2/index.d.ts +100 -0
- package/dist/oauth2/index.mjs +357 -0
- package/dist/shared/core.BJPBStdk.d.ts +1693 -0
- package/dist/shared/core.Bl6TpxyD.d.mts +181 -0
- package/dist/shared/core.Bqe5IGAi.d.ts +13 -0
- package/dist/shared/core.BwoNUcJQ.d.cts +53 -0
- package/dist/shared/core.BwoNUcJQ.d.mts +53 -0
- package/dist/shared/core.BwoNUcJQ.d.ts +53 -0
- package/dist/shared/core.CajxAutx.d.cts +143 -0
- package/dist/shared/core.CajxAutx.d.mts +143 -0
- package/dist/shared/core.CajxAutx.d.ts +143 -0
- package/dist/shared/core.CkkLHQWc.d.mts +1693 -0
- package/dist/shared/core.DkdZ1o38.d.ts +181 -0
- package/dist/shared/core.Dl-70uns.d.cts +84 -0
- package/dist/shared/core.Dl-70uns.d.mts +84 -0
- package/dist/shared/core.Dl-70uns.d.ts +84 -0
- package/dist/shared/core.DyEdx0m7.d.cts +181 -0
- package/dist/shared/core.E9DfzGLz.d.mts +13 -0
- package/dist/shared/core.HqYn20Fi.d.cts +13 -0
- package/dist/shared/core.gYIBmdi1.d.cts +1693 -0
- package/dist/social-providers/index.cjs +2793 -0
- package/dist/social-providers/index.d.cts +3903 -0
- package/dist/social-providers/index.d.mts +3903 -0
- package/dist/social-providers/index.d.ts +3903 -0
- package/dist/social-providers/index.mjs +2743 -0
- package/dist/utils/index.cjs +7 -0
- package/dist/utils/index.d.cts +10 -0
- package/dist/utils/index.d.mts +10 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.mjs +5 -0
- package/package.json +109 -2
- package/src/db/adapter/index.ts +448 -0
- package/src/db/index.ts +13 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +34 -0
- package/src/db/schema/rate-limit.ts +21 -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 +50 -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.test.ts +33 -0
- package/src/env/logger.ts +145 -0
- package/src/error/codes.ts +31 -0
- package/src/error/index.ts +11 -0
- package/src/index.ts +1 -1
- package/src/middleware/index.ts +33 -0
- package/src/oauth2/client-credentials-token.ts +102 -0
- package/src/oauth2/create-authorization-url.ts +85 -0
- package/src/oauth2/index.ts +22 -0
- package/src/oauth2/oauth-provider.ts +194 -0
- package/src/oauth2/refresh-access-token.ts +124 -0
- package/src/oauth2/utils.ts +36 -0
- package/src/oauth2/validate-authorization-code.ts +156 -0
- package/src/social-providers/apple.ts +213 -0
- package/src/social-providers/atlassian.ts +130 -0
- package/src/social-providers/cognito.ts +269 -0
- package/src/social-providers/discord.ts +172 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +204 -0
- package/src/social-providers/figma.ts +115 -0
- package/src/social-providers/github.ts +154 -0
- package/src/social-providers/gitlab.ts +152 -0
- package/src/social-providers/google.ts +171 -0
- package/src/social-providers/huggingface.ts +116 -0
- package/src/social-providers/index.ts +118 -0
- package/src/social-providers/kakao.ts +178 -0
- package/src/social-providers/kick.ts +95 -0
- package/src/social-providers/line.ts +169 -0
- package/src/social-providers/linear.ts +120 -0
- package/src/social-providers/linkedin.ts +110 -0
- package/src/social-providers/microsoft-entra-id.ts +243 -0
- package/src/social-providers/naver.ts +112 -0
- package/src/social-providers/notion.ts +106 -0
- package/src/social-providers/paypal.ts +261 -0
- package/src/social-providers/reddit.ts +122 -0
- package/src/social-providers/roblox.ts +110 -0
- package/src/social-providers/salesforce.ts +157 -0
- package/src/social-providers/slack.ts +114 -0
- package/src/social-providers/spotify.ts +93 -0
- package/src/social-providers/tiktok.ts +211 -0
- package/src/social-providers/twitch.ts +111 -0
- package/src/social-providers/twitter.ts +194 -0
- package/src/social-providers/vk.ts +128 -0
- package/src/social-providers/zoom.ts +218 -0
- package/src/types/context.ts +313 -0
- package/src/types/cookie.ts +7 -0
- package/src/types/helper.ts +5 -0
- package/src/types/index.ts +20 -1
- package/src/types/init-options.ts +1161 -0
- package/src/types/plugin-client.ts +69 -0
- package/src/types/plugin.ts +134 -0
- package/src/utils/error-codes.ts +51 -0
- package/src/utils/index.ts +1 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { BetterAuthPlugin } from "./plugin";
|
|
2
|
+
import type {
|
|
3
|
+
BetterFetch,
|
|
4
|
+
BetterFetchOption,
|
|
5
|
+
BetterFetchPlugin,
|
|
6
|
+
} from "@better-fetch/fetch";
|
|
7
|
+
import type { LiteralString } from "./helper";
|
|
8
|
+
import type { BetterAuthOptions } from "./init-options";
|
|
9
|
+
import type { WritableAtom, Atom } from "nanostores";
|
|
10
|
+
|
|
11
|
+
export interface ClientStore {
|
|
12
|
+
notify: (signal: string) => void;
|
|
13
|
+
listen: (signal: string, listener: () => void) => void;
|
|
14
|
+
atoms: Record<string, WritableAtom<any>>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type ClientAtomListener = {
|
|
18
|
+
matcher: (path: string) => boolean;
|
|
19
|
+
signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface BetterAuthClientOptions {
|
|
23
|
+
fetchOptions?: BetterFetchOption;
|
|
24
|
+
plugins?: BetterAuthClientPlugin[];
|
|
25
|
+
baseURL?: string;
|
|
26
|
+
basePath?: string;
|
|
27
|
+
disableDefaultFetchPlugins?: boolean;
|
|
28
|
+
$InferAuth?: BetterAuthOptions;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface BetterAuthClientPlugin {
|
|
32
|
+
id: LiteralString;
|
|
33
|
+
/**
|
|
34
|
+
* only used for type inference. don't pass the
|
|
35
|
+
* actual plugin
|
|
36
|
+
*/
|
|
37
|
+
$InferServerPlugin?: BetterAuthPlugin;
|
|
38
|
+
/**
|
|
39
|
+
* Custom actions
|
|
40
|
+
*/
|
|
41
|
+
getActions?: (
|
|
42
|
+
$fetch: BetterFetch,
|
|
43
|
+
$store: ClientStore,
|
|
44
|
+
/**
|
|
45
|
+
* better-auth client options
|
|
46
|
+
*/
|
|
47
|
+
options: BetterAuthClientOptions | undefined,
|
|
48
|
+
) => Record<string, any>;
|
|
49
|
+
/**
|
|
50
|
+
* State atoms that'll be resolved by each framework
|
|
51
|
+
* auth store.
|
|
52
|
+
*/
|
|
53
|
+
getAtoms?: ($fetch: BetterFetch) => Record<string, Atom<any>>;
|
|
54
|
+
/**
|
|
55
|
+
* specify path methods for server plugin inferred
|
|
56
|
+
* endpoints to force a specific method.
|
|
57
|
+
*/
|
|
58
|
+
pathMethods?: Record<string, "POST" | "GET">;
|
|
59
|
+
/**
|
|
60
|
+
* Better fetch plugins
|
|
61
|
+
*/
|
|
62
|
+
fetchPlugins?: BetterFetchPlugin[];
|
|
63
|
+
/**
|
|
64
|
+
* a list of recaller based on a matcher function.
|
|
65
|
+
* The signal name needs to match a signal in this
|
|
66
|
+
* plugin or any plugin the user might have added.
|
|
67
|
+
*/
|
|
68
|
+
atomListeners?: ClientAtomListener[];
|
|
69
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Migration } from "kysely";
|
|
2
|
+
import type { AuthContext } from "./context";
|
|
3
|
+
import type {
|
|
4
|
+
Endpoint,
|
|
5
|
+
EndpointContext,
|
|
6
|
+
InputContext,
|
|
7
|
+
Middleware,
|
|
8
|
+
} from "better-call";
|
|
9
|
+
import type { BetterAuthPluginDBSchema } from "../db";
|
|
10
|
+
import type { LiteralString } from "./helper";
|
|
11
|
+
import type { BetterAuthOptions } from "./init-options";
|
|
12
|
+
import type { AuthMiddleware } from "../middleware";
|
|
13
|
+
|
|
14
|
+
type Awaitable<T> = T | Promise<T>;
|
|
15
|
+
type DeepPartial<T> = T extends Function
|
|
16
|
+
? T
|
|
17
|
+
: T extends object
|
|
18
|
+
? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
19
|
+
: T;
|
|
20
|
+
|
|
21
|
+
type HookEndpointContext = EndpointContext<string, any> &
|
|
22
|
+
Omit<InputContext<string, any>, "method"> & {
|
|
23
|
+
context: AuthContext & {
|
|
24
|
+
returned?: unknown;
|
|
25
|
+
responseHeaders?: Headers;
|
|
26
|
+
};
|
|
27
|
+
headers?: Headers;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type BetterAuthPlugin = {
|
|
31
|
+
id: LiteralString;
|
|
32
|
+
/**
|
|
33
|
+
* The init function is called when the plugin is initialized.
|
|
34
|
+
* You can return a new context or modify the existing context.
|
|
35
|
+
*/
|
|
36
|
+
init?: (ctx: AuthContext) =>
|
|
37
|
+
| Awaitable<{
|
|
38
|
+
context?: DeepPartial<Omit<AuthContext, "options">>;
|
|
39
|
+
options?: Partial<BetterAuthOptions>;
|
|
40
|
+
}>
|
|
41
|
+
| void
|
|
42
|
+
| Promise<void>;
|
|
43
|
+
endpoints?: {
|
|
44
|
+
[key: string]: Endpoint;
|
|
45
|
+
};
|
|
46
|
+
middlewares?: {
|
|
47
|
+
path: string;
|
|
48
|
+
middleware: Middleware;
|
|
49
|
+
}[];
|
|
50
|
+
onRequest?: (
|
|
51
|
+
request: Request,
|
|
52
|
+
ctx: AuthContext,
|
|
53
|
+
) => Promise<
|
|
54
|
+
| {
|
|
55
|
+
response: Response;
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
request: Request;
|
|
59
|
+
}
|
|
60
|
+
| void
|
|
61
|
+
>;
|
|
62
|
+
onResponse?: (
|
|
63
|
+
response: Response,
|
|
64
|
+
ctx: AuthContext,
|
|
65
|
+
) => Promise<{
|
|
66
|
+
response: Response;
|
|
67
|
+
} | void>;
|
|
68
|
+
hooks?: {
|
|
69
|
+
before?: {
|
|
70
|
+
matcher: (context: HookEndpointContext) => boolean;
|
|
71
|
+
handler: AuthMiddleware;
|
|
72
|
+
}[];
|
|
73
|
+
after?: {
|
|
74
|
+
matcher: (context: HookEndpointContext) => boolean;
|
|
75
|
+
handler: AuthMiddleware;
|
|
76
|
+
}[];
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Schema the plugin needs
|
|
80
|
+
*
|
|
81
|
+
* This will also be used to migrate the database. If the fields are dynamic from the plugins
|
|
82
|
+
* configuration each time the configuration is changed a new migration will be created.
|
|
83
|
+
*
|
|
84
|
+
* NOTE: If you want to create migrations manually using
|
|
85
|
+
* migrations option or any other way you
|
|
86
|
+
* can disable migration per table basis.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* schema: {
|
|
91
|
+
* user: {
|
|
92
|
+
* fields: {
|
|
93
|
+
* email: {
|
|
94
|
+
* type: "string",
|
|
95
|
+
* },
|
|
96
|
+
* emailVerified: {
|
|
97
|
+
* type: "boolean",
|
|
98
|
+
* defaultValue: false,
|
|
99
|
+
* },
|
|
100
|
+
* },
|
|
101
|
+
* }
|
|
102
|
+
* } as AuthPluginSchema
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
schema?: BetterAuthPluginDBSchema;
|
|
106
|
+
/**
|
|
107
|
+
* The migrations of the plugin. If you define schema that will automatically create
|
|
108
|
+
* migrations for you.
|
|
109
|
+
*
|
|
110
|
+
* ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
|
|
111
|
+
* the tables.
|
|
112
|
+
*/
|
|
113
|
+
migrations?: Record<string, Migration>;
|
|
114
|
+
/**
|
|
115
|
+
* The options of the plugin
|
|
116
|
+
*/
|
|
117
|
+
options?: Record<string, any> | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* types to be inferred
|
|
120
|
+
*/
|
|
121
|
+
$Infer?: Record<string, any>;
|
|
122
|
+
/**
|
|
123
|
+
* The rate limit rules to apply to specific paths.
|
|
124
|
+
*/
|
|
125
|
+
rateLimit?: {
|
|
126
|
+
window: number;
|
|
127
|
+
max: number;
|
|
128
|
+
pathMatcher: (path: string) => boolean;
|
|
129
|
+
}[];
|
|
130
|
+
/**
|
|
131
|
+
* The error codes returned by the plugin
|
|
132
|
+
*/
|
|
133
|
+
$ERROR_CODES?: Record<string, string>;
|
|
134
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
type UpperLetter =
|
|
2
|
+
| "A"
|
|
3
|
+
| "B"
|
|
4
|
+
| "C"
|
|
5
|
+
| "D"
|
|
6
|
+
| "E"
|
|
7
|
+
| "F"
|
|
8
|
+
| "G"
|
|
9
|
+
| "H"
|
|
10
|
+
| "I"
|
|
11
|
+
| "J"
|
|
12
|
+
| "K"
|
|
13
|
+
| "L"
|
|
14
|
+
| "M"
|
|
15
|
+
| "N"
|
|
16
|
+
| "O"
|
|
17
|
+
| "P"
|
|
18
|
+
| "Q"
|
|
19
|
+
| "R"
|
|
20
|
+
| "S"
|
|
21
|
+
| "T"
|
|
22
|
+
| "U"
|
|
23
|
+
| "V"
|
|
24
|
+
| "W"
|
|
25
|
+
| "X"
|
|
26
|
+
| "Y"
|
|
27
|
+
| "Z";
|
|
28
|
+
type SpecialCharacter = "_";
|
|
29
|
+
|
|
30
|
+
type IsValidUpperSnakeCase<S extends string> = S extends `${infer F}${infer R}`
|
|
31
|
+
? F extends UpperLetter | SpecialCharacter
|
|
32
|
+
? IsValidUpperSnakeCase<R>
|
|
33
|
+
: false
|
|
34
|
+
: true;
|
|
35
|
+
|
|
36
|
+
type InvalidKeyError<K extends string> =
|
|
37
|
+
`Invalid error code key: "${K}" - must only contain uppercase letters (A-Z) and underscores (_)`;
|
|
38
|
+
|
|
39
|
+
type ValidateErrorCodes<T> = {
|
|
40
|
+
[K in keyof T]: K extends string
|
|
41
|
+
? IsValidUpperSnakeCase<K> extends false
|
|
42
|
+
? InvalidKeyError<K>
|
|
43
|
+
: T[K]
|
|
44
|
+
: T[K];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export function defineErrorCodes<const T extends Record<string, string>>(
|
|
48
|
+
codes: ValidateErrorCodes<T>,
|
|
49
|
+
): T {
|
|
50
|
+
return codes as T;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineErrorCodes } from "./error-codes";
|