@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.
Files changed (130) hide show
  1. package/.turbo/turbo-build.log +60 -9
  2. package/build.config.ts +7 -0
  3. package/dist/db/adapter/index.cjs +2 -0
  4. package/dist/db/adapter/index.d.cts +14 -0
  5. package/dist/db/adapter/index.d.mts +14 -0
  6. package/dist/db/adapter/index.d.ts +14 -0
  7. package/dist/db/adapter/index.mjs +1 -0
  8. package/dist/db/index.cjs +89 -0
  9. package/dist/db/index.d.cts +16 -107
  10. package/dist/db/index.d.mts +16 -107
  11. package/dist/db/index.d.ts +16 -107
  12. package/dist/db/index.mjs +69 -0
  13. package/dist/env/index.cjs +312 -0
  14. package/dist/env/index.d.cts +36 -0
  15. package/dist/env/index.d.mts +36 -0
  16. package/dist/env/index.d.ts +36 -0
  17. package/dist/env/index.mjs +297 -0
  18. package/dist/error/index.cjs +44 -0
  19. package/dist/error/index.d.cts +33 -0
  20. package/dist/error/index.d.mts +33 -0
  21. package/dist/error/index.d.ts +33 -0
  22. package/dist/error/index.mjs +41 -0
  23. package/dist/index.d.cts +179 -1
  24. package/dist/index.d.mts +179 -1
  25. package/dist/index.d.ts +179 -1
  26. package/dist/middleware/index.cjs +25 -0
  27. package/dist/middleware/index.d.cts +14 -0
  28. package/dist/middleware/index.d.mts +14 -0
  29. package/dist/middleware/index.d.ts +14 -0
  30. package/dist/middleware/index.mjs +21 -0
  31. package/dist/oauth2/index.cjs +368 -0
  32. package/dist/oauth2/index.d.cts +100 -0
  33. package/dist/oauth2/index.d.mts +100 -0
  34. package/dist/oauth2/index.d.ts +100 -0
  35. package/dist/oauth2/index.mjs +357 -0
  36. package/dist/shared/core.BJPBStdk.d.ts +1693 -0
  37. package/dist/shared/core.Bl6TpxyD.d.mts +181 -0
  38. package/dist/shared/core.Bqe5IGAi.d.ts +13 -0
  39. package/dist/shared/core.BwoNUcJQ.d.cts +53 -0
  40. package/dist/shared/core.BwoNUcJQ.d.mts +53 -0
  41. package/dist/shared/core.BwoNUcJQ.d.ts +53 -0
  42. package/dist/shared/core.CajxAutx.d.cts +143 -0
  43. package/dist/shared/core.CajxAutx.d.mts +143 -0
  44. package/dist/shared/core.CajxAutx.d.ts +143 -0
  45. package/dist/shared/core.CkkLHQWc.d.mts +1693 -0
  46. package/dist/shared/core.DkdZ1o38.d.ts +181 -0
  47. package/dist/shared/core.Dl-70uns.d.cts +84 -0
  48. package/dist/shared/core.Dl-70uns.d.mts +84 -0
  49. package/dist/shared/core.Dl-70uns.d.ts +84 -0
  50. package/dist/shared/core.DyEdx0m7.d.cts +181 -0
  51. package/dist/shared/core.E9DfzGLz.d.mts +13 -0
  52. package/dist/shared/core.HqYn20Fi.d.cts +13 -0
  53. package/dist/shared/core.gYIBmdi1.d.cts +1693 -0
  54. package/dist/social-providers/index.cjs +2793 -0
  55. package/dist/social-providers/index.d.cts +3903 -0
  56. package/dist/social-providers/index.d.mts +3903 -0
  57. package/dist/social-providers/index.d.ts +3903 -0
  58. package/dist/social-providers/index.mjs +2743 -0
  59. package/dist/utils/index.cjs +7 -0
  60. package/dist/utils/index.d.cts +10 -0
  61. package/dist/utils/index.d.mts +10 -0
  62. package/dist/utils/index.d.ts +10 -0
  63. package/dist/utils/index.mjs +5 -0
  64. package/package.json +109 -2
  65. package/src/db/adapter/index.ts +448 -0
  66. package/src/db/index.ts +13 -0
  67. package/src/db/plugin.ts +11 -0
  68. package/src/db/schema/account.ts +34 -0
  69. package/src/db/schema/rate-limit.ts +21 -0
  70. package/src/db/schema/session.ts +17 -0
  71. package/src/db/schema/shared.ts +7 -0
  72. package/src/db/schema/user.ts +16 -0
  73. package/src/db/schema/verification.ts +15 -0
  74. package/src/db/type.ts +50 -0
  75. package/src/env/color-depth.ts +172 -0
  76. package/src/env/env-impl.ts +123 -0
  77. package/src/env/index.ts +23 -0
  78. package/src/env/logger.test.ts +33 -0
  79. package/src/env/logger.ts +145 -0
  80. package/src/error/codes.ts +31 -0
  81. package/src/error/index.ts +11 -0
  82. package/src/index.ts +1 -1
  83. package/src/middleware/index.ts +33 -0
  84. package/src/oauth2/client-credentials-token.ts +102 -0
  85. package/src/oauth2/create-authorization-url.ts +85 -0
  86. package/src/oauth2/index.ts +22 -0
  87. package/src/oauth2/oauth-provider.ts +194 -0
  88. package/src/oauth2/refresh-access-token.ts +124 -0
  89. package/src/oauth2/utils.ts +36 -0
  90. package/src/oauth2/validate-authorization-code.ts +156 -0
  91. package/src/social-providers/apple.ts +213 -0
  92. package/src/social-providers/atlassian.ts +130 -0
  93. package/src/social-providers/cognito.ts +269 -0
  94. package/src/social-providers/discord.ts +172 -0
  95. package/src/social-providers/dropbox.ts +112 -0
  96. package/src/social-providers/facebook.ts +204 -0
  97. package/src/social-providers/figma.ts +115 -0
  98. package/src/social-providers/github.ts +154 -0
  99. package/src/social-providers/gitlab.ts +152 -0
  100. package/src/social-providers/google.ts +171 -0
  101. package/src/social-providers/huggingface.ts +116 -0
  102. package/src/social-providers/index.ts +118 -0
  103. package/src/social-providers/kakao.ts +178 -0
  104. package/src/social-providers/kick.ts +95 -0
  105. package/src/social-providers/line.ts +169 -0
  106. package/src/social-providers/linear.ts +120 -0
  107. package/src/social-providers/linkedin.ts +110 -0
  108. package/src/social-providers/microsoft-entra-id.ts +243 -0
  109. package/src/social-providers/naver.ts +112 -0
  110. package/src/social-providers/notion.ts +106 -0
  111. package/src/social-providers/paypal.ts +261 -0
  112. package/src/social-providers/reddit.ts +122 -0
  113. package/src/social-providers/roblox.ts +110 -0
  114. package/src/social-providers/salesforce.ts +157 -0
  115. package/src/social-providers/slack.ts +114 -0
  116. package/src/social-providers/spotify.ts +93 -0
  117. package/src/social-providers/tiktok.ts +211 -0
  118. package/src/social-providers/twitch.ts +111 -0
  119. package/src/social-providers/twitter.ts +194 -0
  120. package/src/social-providers/vk.ts +128 -0
  121. package/src/social-providers/zoom.ts +218 -0
  122. package/src/types/context.ts +313 -0
  123. package/src/types/cookie.ts +7 -0
  124. package/src/types/helper.ts +5 -0
  125. package/src/types/index.ts +20 -1
  126. package/src/types/init-options.ts +1161 -0
  127. package/src/types/plugin-client.ts +69 -0
  128. package/src/types/plugin.ts +134 -0
  129. package/src/utils/error-codes.ts +51 -0
  130. package/src/utils/index.ts +1 -0
@@ -0,0 +1,297 @@
1
+ const _envShim = /* @__PURE__ */ Object.create(null);
2
+ const _getEnv = (useShim) => globalThis.process?.env || //@ts-expect-error
3
+ globalThis.Deno?.env.toObject() || //@ts-expect-error
4
+ globalThis.__env__ || (useShim ? _envShim : globalThis);
5
+ const env = new Proxy(_envShim, {
6
+ get(_, prop) {
7
+ const env2 = _getEnv();
8
+ return env2[prop] ?? _envShim[prop];
9
+ },
10
+ has(_, prop) {
11
+ const env2 = _getEnv();
12
+ return prop in env2 || prop in _envShim;
13
+ },
14
+ set(_, prop, value) {
15
+ const env2 = _getEnv(true);
16
+ env2[prop] = value;
17
+ return true;
18
+ },
19
+ deleteProperty(_, prop) {
20
+ if (!prop) {
21
+ return false;
22
+ }
23
+ const env2 = _getEnv(true);
24
+ delete env2[prop];
25
+ return true;
26
+ },
27
+ ownKeys() {
28
+ const env2 = _getEnv(true);
29
+ return Object.keys(env2);
30
+ }
31
+ });
32
+ function toBoolean(val) {
33
+ return val ? val !== "false" : false;
34
+ }
35
+ const nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
36
+ const isProduction = nodeENV === "production";
37
+ const isDevelopment = nodeENV === "dev" || nodeENV === "development";
38
+ const isTest = () => nodeENV === "test" || toBoolean(env.TEST);
39
+ function getEnvVar(key, fallback) {
40
+ if (typeof process !== "undefined" && process.env) {
41
+ return process.env[key] ?? fallback;
42
+ }
43
+ if (typeof Deno !== "undefined") {
44
+ return Deno.env.get(key) ?? fallback;
45
+ }
46
+ if (typeof Bun !== "undefined") {
47
+ return Bun.env[key] ?? fallback;
48
+ }
49
+ return fallback;
50
+ }
51
+ function getBooleanEnvVar(key, fallback = true) {
52
+ const value = getEnvVar(key);
53
+ if (!value) return fallback;
54
+ return value !== "0" && value.toLowerCase() !== "false" && value !== "";
55
+ }
56
+ const ENV = Object.freeze({
57
+ get BETTER_AUTH_SECRET() {
58
+ return getEnvVar("BETTER_AUTH_SECRET");
59
+ },
60
+ get AUTH_SECRET() {
61
+ return getEnvVar("AUTH_SECRET");
62
+ },
63
+ get BETTER_AUTH_TELEMETRY() {
64
+ return getEnvVar("BETTER_AUTH_TELEMETRY");
65
+ },
66
+ get BETTER_AUTH_TELEMETRY_ID() {
67
+ return getEnvVar("BETTER_AUTH_TELEMETRY_ID");
68
+ },
69
+ get NODE_ENV() {
70
+ return getEnvVar("NODE_ENV", "development");
71
+ },
72
+ get PACKAGE_VERSION() {
73
+ return getEnvVar("PACKAGE_VERSION", "0.0.0");
74
+ },
75
+ get BETTER_AUTH_TELEMETRY_ENDPOINT() {
76
+ return getEnvVar(
77
+ "BETTER_AUTH_TELEMETRY_ENDPOINT",
78
+ "https://telemetry.better-auth.com/v1/track"
79
+ );
80
+ }
81
+ });
82
+
83
+ const COLORS_2 = 1;
84
+ const COLORS_16 = 4;
85
+ const COLORS_256 = 8;
86
+ const COLORS_16m = 24;
87
+ const TERM_ENVS = {
88
+ eterm: COLORS_16,
89
+ cons25: COLORS_16,
90
+ console: COLORS_16,
91
+ cygwin: COLORS_16,
92
+ dtterm: COLORS_16,
93
+ gnome: COLORS_16,
94
+ hurd: COLORS_16,
95
+ jfbterm: COLORS_16,
96
+ konsole: COLORS_16,
97
+ kterm: COLORS_16,
98
+ mlterm: COLORS_16,
99
+ mosh: COLORS_16m,
100
+ putty: COLORS_16,
101
+ st: COLORS_16,
102
+ // http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html
103
+ "rxvt-unicode-24bit": COLORS_16m,
104
+ // https://bugs.launchpad.net/terminator/+bug/1030562
105
+ terminator: COLORS_16m,
106
+ "xterm-kitty": COLORS_16m
107
+ };
108
+ const CI_ENVS_MAP = new Map(
109
+ Object.entries({
110
+ APPVEYOR: COLORS_256,
111
+ BUILDKITE: COLORS_256,
112
+ CIRCLECI: COLORS_16m,
113
+ DRONE: COLORS_256,
114
+ GITEA_ACTIONS: COLORS_16m,
115
+ GITHUB_ACTIONS: COLORS_16m,
116
+ GITLAB_CI: COLORS_256,
117
+ TRAVIS: COLORS_256
118
+ })
119
+ );
120
+ const TERM_ENVS_REG_EXP = [
121
+ /ansi/,
122
+ /color/,
123
+ /linux/,
124
+ /direct/,
125
+ /^con[0-9]*x[0-9]/,
126
+ /^rxvt/,
127
+ /^screen/,
128
+ /^xterm/,
129
+ /^vt100/,
130
+ /^vt220/
131
+ ];
132
+ function getColorDepth() {
133
+ if (getEnvVar("FORCE_COLOR") !== void 0) {
134
+ switch (getEnvVar("FORCE_COLOR")) {
135
+ case "":
136
+ case "1":
137
+ case "true":
138
+ return COLORS_16;
139
+ case "2":
140
+ return COLORS_256;
141
+ case "3":
142
+ return COLORS_16m;
143
+ default:
144
+ return COLORS_2;
145
+ }
146
+ }
147
+ if (getEnvVar("NODE_DISABLE_COLORS") !== void 0 && getEnvVar("NODE_DISABLE_COLORS") !== "" || // See https://no-color.org/
148
+ getEnvVar("NO_COLOR") !== void 0 && getEnvVar("NO_COLOR") !== "" || // The "dumb" special terminal, as defined by terminfo, doesn't support
149
+ // ANSI color control codes.
150
+ // See https://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
151
+ getEnvVar("TERM") === "dumb") {
152
+ return COLORS_2;
153
+ }
154
+ if (getEnvVar("TMUX")) {
155
+ return COLORS_16m;
156
+ }
157
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
158
+ return COLORS_16;
159
+ }
160
+ if ("CI" in env) {
161
+ for (const { 0: envName, 1: colors } of CI_ENVS_MAP) {
162
+ if (envName in env) {
163
+ return colors;
164
+ }
165
+ }
166
+ if (getEnvVar("CI_NAME") === "codeship") {
167
+ return COLORS_256;
168
+ }
169
+ return COLORS_2;
170
+ }
171
+ if ("TEAMCITY_VERSION" in env) {
172
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(
173
+ getEnvVar("TEAMCITY_VERSION")
174
+ ) !== null ? COLORS_16 : COLORS_2;
175
+ }
176
+ switch (getEnvVar("TERM_PROGRAM")) {
177
+ case "iTerm.app":
178
+ if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) {
179
+ return COLORS_256;
180
+ }
181
+ return COLORS_16m;
182
+ case "HyperTerm":
183
+ case "MacTerm":
184
+ return COLORS_16m;
185
+ case "Apple_Terminal":
186
+ return COLORS_256;
187
+ }
188
+ if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") {
189
+ return COLORS_16m;
190
+ }
191
+ if (getEnvVar("TERM")) {
192
+ if (/truecolor/.exec(getEnvVar("TERM")) !== null) {
193
+ return COLORS_16m;
194
+ }
195
+ if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) {
196
+ return COLORS_256;
197
+ }
198
+ const termEnv = getEnvVar("TERM").toLowerCase();
199
+ if (TERM_ENVS[termEnv]) {
200
+ return TERM_ENVS[termEnv];
201
+ }
202
+ if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) {
203
+ return COLORS_16;
204
+ }
205
+ }
206
+ if (getEnvVar("COLORTERM")) {
207
+ return COLORS_16;
208
+ }
209
+ return COLORS_2;
210
+ }
211
+
212
+ const TTY_COLORS = {
213
+ reset: "\x1B[0m",
214
+ bright: "\x1B[1m",
215
+ dim: "\x1B[2m",
216
+ undim: "\x1B[22m",
217
+ underscore: "\x1B[4m",
218
+ blink: "\x1B[5m",
219
+ reverse: "\x1B[7m",
220
+ hidden: "\x1B[8m",
221
+ fg: {
222
+ black: "\x1B[30m",
223
+ red: "\x1B[31m",
224
+ green: "\x1B[32m",
225
+ yellow: "\x1B[33m",
226
+ blue: "\x1B[34m",
227
+ magenta: "\x1B[35m",
228
+ cyan: "\x1B[36m",
229
+ white: "\x1B[37m"
230
+ },
231
+ bg: {
232
+ black: "\x1B[40m",
233
+ red: "\x1B[41m",
234
+ green: "\x1B[42m",
235
+ yellow: "\x1B[43m",
236
+ blue: "\x1B[44m",
237
+ magenta: "\x1B[45m",
238
+ cyan: "\x1B[46m",
239
+ white: "\x1B[47m"
240
+ }
241
+ };
242
+ const levels = ["info", "success", "warn", "error", "debug"];
243
+ function shouldPublishLog(currentLogLevel, logLevel) {
244
+ return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
245
+ }
246
+ const levelColors = {
247
+ info: TTY_COLORS.fg.blue,
248
+ success: TTY_COLORS.fg.green,
249
+ warn: TTY_COLORS.fg.yellow,
250
+ error: TTY_COLORS.fg.red,
251
+ debug: TTY_COLORS.fg.magenta
252
+ };
253
+ const formatMessage = (level, message, colorsEnabled) => {
254
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
255
+ if (colorsEnabled) {
256
+ return `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${levelColors[level]}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${TTY_COLORS.reset} ${message}`;
257
+ }
258
+ return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
259
+ };
260
+ const createLogger = (options) => {
261
+ const enabled = options?.disabled !== true;
262
+ const logLevel = options?.level ?? "error";
263
+ const isDisableColorsSpecified = options?.disableColors !== void 0;
264
+ const colorsEnabled = isDisableColorsSpecified ? !options.disableColors : getColorDepth() !== 1;
265
+ const LogFunc = (level, message, args = []) => {
266
+ if (!enabled || !shouldPublishLog(logLevel, level)) {
267
+ return;
268
+ }
269
+ const formattedMessage = formatMessage(level, message, colorsEnabled);
270
+ if (!options || typeof options.log !== "function") {
271
+ if (level === "error") {
272
+ console.error(formattedMessage, ...args);
273
+ } else if (level === "warn") {
274
+ console.warn(formattedMessage, ...args);
275
+ } else {
276
+ console.log(formattedMessage, ...args);
277
+ }
278
+ return;
279
+ }
280
+ options.log(level === "success" ? "info" : level, message, ...args);
281
+ };
282
+ const logger2 = Object.fromEntries(
283
+ levels.map((level) => [
284
+ level,
285
+ (...[message, ...args]) => LogFunc(level, message, args)
286
+ ])
287
+ );
288
+ return {
289
+ ...logger2,
290
+ get level() {
291
+ return logLevel;
292
+ }
293
+ };
294
+ };
295
+ const logger = createLogger();
296
+
297
+ export { ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const utils = require('@better-auth/core/utils');
4
+
5
+ const BASE_ERROR_CODES = utils.defineErrorCodes({
6
+ USER_NOT_FOUND: "User not found",
7
+ FAILED_TO_CREATE_USER: "Failed to create user",
8
+ FAILED_TO_CREATE_SESSION: "Failed to create session",
9
+ FAILED_TO_UPDATE_USER: "Failed to update user",
10
+ FAILED_TO_GET_SESSION: "Failed to get session",
11
+ INVALID_PASSWORD: "Invalid password",
12
+ INVALID_EMAIL: "Invalid email",
13
+ INVALID_EMAIL_OR_PASSWORD: "Invalid email or password",
14
+ SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked",
15
+ PROVIDER_NOT_FOUND: "Provider not found",
16
+ INVALID_TOKEN: "Invalid token",
17
+ ID_TOKEN_NOT_SUPPORTED: "id_token not supported",
18
+ FAILED_TO_GET_USER_INFO: "Failed to get user info",
19
+ USER_EMAIL_NOT_FOUND: "User email not found",
20
+ EMAIL_NOT_VERIFIED: "Email not verified",
21
+ PASSWORD_TOO_SHORT: "Password too short",
22
+ PASSWORD_TOO_LONG: "Password too long",
23
+ USER_ALREADY_EXISTS: "User already exists.",
24
+ USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.",
25
+ EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated",
26
+ CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found",
27
+ SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.",
28
+ FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account",
29
+ ACCOUNT_NOT_FOUND: "Account not found",
30
+ USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account."
31
+ });
32
+
33
+ class BetterAuthError extends Error {
34
+ constructor(message, cause) {
35
+ super(message);
36
+ this.name = "BetterAuthError";
37
+ this.message = message;
38
+ this.cause = cause;
39
+ this.stack = "";
40
+ }
41
+ }
42
+
43
+ exports.BASE_ERROR_CODES = BASE_ERROR_CODES;
44
+ exports.BetterAuthError = BetterAuthError;
@@ -0,0 +1,33 @@
1
+ declare const BASE_ERROR_CODES: {
2
+ readonly USER_NOT_FOUND: "User not found";
3
+ readonly FAILED_TO_CREATE_USER: "Failed to create user";
4
+ readonly FAILED_TO_CREATE_SESSION: "Failed to create session";
5
+ readonly FAILED_TO_UPDATE_USER: "Failed to update user";
6
+ readonly FAILED_TO_GET_SESSION: "Failed to get session";
7
+ readonly INVALID_PASSWORD: "Invalid password";
8
+ readonly INVALID_EMAIL: "Invalid email";
9
+ readonly INVALID_EMAIL_OR_PASSWORD: "Invalid email or password";
10
+ readonly SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked";
11
+ readonly PROVIDER_NOT_FOUND: "Provider not found";
12
+ readonly INVALID_TOKEN: "Invalid token";
13
+ readonly ID_TOKEN_NOT_SUPPORTED: "id_token not supported";
14
+ readonly FAILED_TO_GET_USER_INFO: "Failed to get user info";
15
+ readonly USER_EMAIL_NOT_FOUND: "User email not found";
16
+ readonly EMAIL_NOT_VERIFIED: "Email not verified";
17
+ readonly PASSWORD_TOO_SHORT: "Password too short";
18
+ readonly PASSWORD_TOO_LONG: "Password too long";
19
+ readonly USER_ALREADY_EXISTS: "User already exists.";
20
+ readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.";
21
+ readonly EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated";
22
+ readonly CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found";
23
+ readonly SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.";
24
+ readonly FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account";
25
+ readonly ACCOUNT_NOT_FOUND: "Account not found";
26
+ readonly USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.";
27
+ };
28
+
29
+ declare class BetterAuthError extends Error {
30
+ constructor(message: string, cause?: string);
31
+ }
32
+
33
+ export { BASE_ERROR_CODES, BetterAuthError };
@@ -0,0 +1,33 @@
1
+ declare const BASE_ERROR_CODES: {
2
+ readonly USER_NOT_FOUND: "User not found";
3
+ readonly FAILED_TO_CREATE_USER: "Failed to create user";
4
+ readonly FAILED_TO_CREATE_SESSION: "Failed to create session";
5
+ readonly FAILED_TO_UPDATE_USER: "Failed to update user";
6
+ readonly FAILED_TO_GET_SESSION: "Failed to get session";
7
+ readonly INVALID_PASSWORD: "Invalid password";
8
+ readonly INVALID_EMAIL: "Invalid email";
9
+ readonly INVALID_EMAIL_OR_PASSWORD: "Invalid email or password";
10
+ readonly SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked";
11
+ readonly PROVIDER_NOT_FOUND: "Provider not found";
12
+ readonly INVALID_TOKEN: "Invalid token";
13
+ readonly ID_TOKEN_NOT_SUPPORTED: "id_token not supported";
14
+ readonly FAILED_TO_GET_USER_INFO: "Failed to get user info";
15
+ readonly USER_EMAIL_NOT_FOUND: "User email not found";
16
+ readonly EMAIL_NOT_VERIFIED: "Email not verified";
17
+ readonly PASSWORD_TOO_SHORT: "Password too short";
18
+ readonly PASSWORD_TOO_LONG: "Password too long";
19
+ readonly USER_ALREADY_EXISTS: "User already exists.";
20
+ readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.";
21
+ readonly EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated";
22
+ readonly CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found";
23
+ readonly SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.";
24
+ readonly FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account";
25
+ readonly ACCOUNT_NOT_FOUND: "Account not found";
26
+ readonly USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.";
27
+ };
28
+
29
+ declare class BetterAuthError extends Error {
30
+ constructor(message: string, cause?: string);
31
+ }
32
+
33
+ export { BASE_ERROR_CODES, BetterAuthError };
@@ -0,0 +1,33 @@
1
+ declare const BASE_ERROR_CODES: {
2
+ readonly USER_NOT_FOUND: "User not found";
3
+ readonly FAILED_TO_CREATE_USER: "Failed to create user";
4
+ readonly FAILED_TO_CREATE_SESSION: "Failed to create session";
5
+ readonly FAILED_TO_UPDATE_USER: "Failed to update user";
6
+ readonly FAILED_TO_GET_SESSION: "Failed to get session";
7
+ readonly INVALID_PASSWORD: "Invalid password";
8
+ readonly INVALID_EMAIL: "Invalid email";
9
+ readonly INVALID_EMAIL_OR_PASSWORD: "Invalid email or password";
10
+ readonly SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked";
11
+ readonly PROVIDER_NOT_FOUND: "Provider not found";
12
+ readonly INVALID_TOKEN: "Invalid token";
13
+ readonly ID_TOKEN_NOT_SUPPORTED: "id_token not supported";
14
+ readonly FAILED_TO_GET_USER_INFO: "Failed to get user info";
15
+ readonly USER_EMAIL_NOT_FOUND: "User email not found";
16
+ readonly EMAIL_NOT_VERIFIED: "Email not verified";
17
+ readonly PASSWORD_TOO_SHORT: "Password too short";
18
+ readonly PASSWORD_TOO_LONG: "Password too long";
19
+ readonly USER_ALREADY_EXISTS: "User already exists.";
20
+ readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.";
21
+ readonly EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated";
22
+ readonly CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found";
23
+ readonly SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.";
24
+ readonly FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account";
25
+ readonly ACCOUNT_NOT_FOUND: "Account not found";
26
+ readonly USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.";
27
+ };
28
+
29
+ declare class BetterAuthError extends Error {
30
+ constructor(message: string, cause?: string);
31
+ }
32
+
33
+ export { BASE_ERROR_CODES, BetterAuthError };
@@ -0,0 +1,41 @@
1
+ import { defineErrorCodes } from '@better-auth/core/utils';
2
+
3
+ const BASE_ERROR_CODES = defineErrorCodes({
4
+ USER_NOT_FOUND: "User not found",
5
+ FAILED_TO_CREATE_USER: "Failed to create user",
6
+ FAILED_TO_CREATE_SESSION: "Failed to create session",
7
+ FAILED_TO_UPDATE_USER: "Failed to update user",
8
+ FAILED_TO_GET_SESSION: "Failed to get session",
9
+ INVALID_PASSWORD: "Invalid password",
10
+ INVALID_EMAIL: "Invalid email",
11
+ INVALID_EMAIL_OR_PASSWORD: "Invalid email or password",
12
+ SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked",
13
+ PROVIDER_NOT_FOUND: "Provider not found",
14
+ INVALID_TOKEN: "Invalid token",
15
+ ID_TOKEN_NOT_SUPPORTED: "id_token not supported",
16
+ FAILED_TO_GET_USER_INFO: "Failed to get user info",
17
+ USER_EMAIL_NOT_FOUND: "User email not found",
18
+ EMAIL_NOT_VERIFIED: "Email not verified",
19
+ PASSWORD_TOO_SHORT: "Password too short",
20
+ PASSWORD_TOO_LONG: "Password too long",
21
+ USER_ALREADY_EXISTS: "User already exists.",
22
+ USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.",
23
+ EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated",
24
+ CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found",
25
+ SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.",
26
+ FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account",
27
+ ACCOUNT_NOT_FOUND: "Account not found",
28
+ USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account."
29
+ });
30
+
31
+ class BetterAuthError extends Error {
32
+ constructor(message, cause) {
33
+ super(message);
34
+ this.name = "BetterAuthError";
35
+ this.message = message;
36
+ this.cause = cause;
37
+ this.stack = "";
38
+ }
39
+ }
40
+
41
+ export { BASE_ERROR_CODES, BetterAuthError };
package/dist/index.d.cts CHANGED
@@ -1,2 +1,180 @@
1
+ import { L as LiteralString } from './shared/core.CajxAutx.cjs';
2
+ export { a as LiteralUnion } from './shared/core.CajxAutx.cjs';
3
+ import { A as AuthContext, B as BetterAuthOptions, a as AuthMiddleware } from './shared/core.gYIBmdi1.cjs';
4
+ export { b as BetterAuthAdvancedOptions, d as BetterAuthCookies, c as BetterAuthRateLimitOptions, G as GenerateIdFn, e as GenericEndpointContext, I as InternalAdapter } from './shared/core.gYIBmdi1.cjs';
5
+ import { Migration } from 'kysely';
6
+ import { Endpoint, Middleware, EndpointContext, InputContext } from 'better-call';
7
+ import { B as BetterAuthPluginDBSchema } from './shared/core.HqYn20Fi.cjs';
8
+ import { BetterFetch, BetterFetchOption, BetterFetchPlugin } from '@better-fetch/fetch';
9
+ import { WritableAtom, Atom } from 'nanostores';
10
+ import 'zod';
11
+ import 'better-sqlite3';
12
+ import './shared/core.Dl-70uns.cjs';
13
+ import 'bun:sqlite';
14
+ import 'node:sqlite';
15
+ import './social-providers/index.cjs';
16
+ import '@better-auth/core/oauth2';
17
+ import './shared/core.DyEdx0m7.cjs';
18
+ import './shared/core.BwoNUcJQ.cjs';
19
+ import '@better-auth/core';
1
20
 
2
- export { };
21
+ type Awaitable<T> = T | Promise<T>;
22
+ type DeepPartial<T> = T extends Function ? T : T extends object ? {
23
+ [K in keyof T]?: DeepPartial<T[K]>;
24
+ } : T;
25
+ type HookEndpointContext = EndpointContext<string, any> & Omit<InputContext<string, any>, "method"> & {
26
+ context: AuthContext & {
27
+ returned?: unknown;
28
+ responseHeaders?: Headers;
29
+ };
30
+ headers?: Headers;
31
+ };
32
+ type BetterAuthPlugin = {
33
+ id: LiteralString;
34
+ /**
35
+ * The init function is called when the plugin is initialized.
36
+ * You can return a new context or modify the existing context.
37
+ */
38
+ init?: (ctx: AuthContext) => Awaitable<{
39
+ context?: DeepPartial<Omit<AuthContext, "options">>;
40
+ options?: Partial<BetterAuthOptions>;
41
+ }> | void | Promise<void>;
42
+ endpoints?: {
43
+ [key: string]: Endpoint;
44
+ };
45
+ middlewares?: {
46
+ path: string;
47
+ middleware: Middleware;
48
+ }[];
49
+ onRequest?: (request: Request, ctx: AuthContext) => Promise<{
50
+ response: Response;
51
+ } | {
52
+ request: Request;
53
+ } | void>;
54
+ onResponse?: (response: Response, ctx: AuthContext) => Promise<{
55
+ response: Response;
56
+ } | void>;
57
+ hooks?: {
58
+ before?: {
59
+ matcher: (context: HookEndpointContext) => boolean;
60
+ handler: AuthMiddleware;
61
+ }[];
62
+ after?: {
63
+ matcher: (context: HookEndpointContext) => boolean;
64
+ handler: AuthMiddleware;
65
+ }[];
66
+ };
67
+ /**
68
+ * Schema the plugin needs
69
+ *
70
+ * This will also be used to migrate the database. If the fields are dynamic from the plugins
71
+ * configuration each time the configuration is changed a new migration will be created.
72
+ *
73
+ * NOTE: If you want to create migrations manually using
74
+ * migrations option or any other way you
75
+ * can disable migration per table basis.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * schema: {
80
+ * user: {
81
+ * fields: {
82
+ * email: {
83
+ * type: "string",
84
+ * },
85
+ * emailVerified: {
86
+ * type: "boolean",
87
+ * defaultValue: false,
88
+ * },
89
+ * },
90
+ * }
91
+ * } as AuthPluginSchema
92
+ * ```
93
+ */
94
+ schema?: BetterAuthPluginDBSchema;
95
+ /**
96
+ * The migrations of the plugin. If you define schema that will automatically create
97
+ * migrations for you.
98
+ *
99
+ * ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
100
+ * the tables.
101
+ */
102
+ migrations?: Record<string, Migration>;
103
+ /**
104
+ * The options of the plugin
105
+ */
106
+ options?: Record<string, any> | undefined;
107
+ /**
108
+ * types to be inferred
109
+ */
110
+ $Infer?: Record<string, any>;
111
+ /**
112
+ * The rate limit rules to apply to specific paths.
113
+ */
114
+ rateLimit?: {
115
+ window: number;
116
+ max: number;
117
+ pathMatcher: (path: string) => boolean;
118
+ }[];
119
+ /**
120
+ * The error codes returned by the plugin
121
+ */
122
+ $ERROR_CODES?: Record<string, string>;
123
+ };
124
+
125
+ interface ClientStore {
126
+ notify: (signal: string) => void;
127
+ listen: (signal: string, listener: () => void) => void;
128
+ atoms: Record<string, WritableAtom<any>>;
129
+ }
130
+ type ClientAtomListener = {
131
+ matcher: (path: string) => boolean;
132
+ signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
133
+ };
134
+ interface BetterAuthClientOptions {
135
+ fetchOptions?: BetterFetchOption;
136
+ plugins?: BetterAuthClientPlugin[];
137
+ baseURL?: string;
138
+ basePath?: string;
139
+ disableDefaultFetchPlugins?: boolean;
140
+ $InferAuth?: BetterAuthOptions;
141
+ }
142
+ interface BetterAuthClientPlugin {
143
+ id: LiteralString;
144
+ /**
145
+ * only used for type inference. don't pass the
146
+ * actual plugin
147
+ */
148
+ $InferServerPlugin?: BetterAuthPlugin;
149
+ /**
150
+ * Custom actions
151
+ */
152
+ getActions?: ($fetch: BetterFetch, $store: ClientStore,
153
+ /**
154
+ * better-auth client options
155
+ */
156
+ options: BetterAuthClientOptions | undefined) => Record<string, any>;
157
+ /**
158
+ * State atoms that'll be resolved by each framework
159
+ * auth store.
160
+ */
161
+ getAtoms?: ($fetch: BetterFetch) => Record<string, Atom<any>>;
162
+ /**
163
+ * specify path methods for server plugin inferred
164
+ * endpoints to force a specific method.
165
+ */
166
+ pathMethods?: Record<string, "POST" | "GET">;
167
+ /**
168
+ * Better fetch plugins
169
+ */
170
+ fetchPlugins?: BetterFetchPlugin[];
171
+ /**
172
+ * a list of recaller based on a matcher function.
173
+ * The signal name needs to match a signal in this
174
+ * plugin or any plugin the user might have added.
175
+ */
176
+ atomListeners?: ClientAtomListener[];
177
+ }
178
+
179
+ export { AuthContext, BetterAuthOptions, LiteralString };
180
+ export type { BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthPlugin, ClientAtomListener, ClientStore };