@better-auth/core 1.4.8 → 1.5.0-beta.1
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 -10
- package/dist/api/index.d.mts +1 -1
- package/dist/context/index.d.mts +1 -1
- package/dist/db/adapter/index.d.mts +1 -1
- package/dist/db/adapter/index.mjs +2 -2
- package/dist/db/index.d.mts +1 -1
- package/dist/error/index.d.mts +188 -26
- package/dist/error/index.mjs +3 -3
- package/dist/{error-CzMAIrPb.mjs → error-Dj5gH2lv.mjs} +37 -3
- package/dist/{index-CBdZH5fV.d.mts → index-oZTwg35a.d.mts} +20 -2
- package/dist/index.d.mts +1 -1
- package/dist/oauth2/index.d.mts +1 -1
- package/dist/social-providers/index.d.mts +1 -1
- package/dist/social-providers/index.mjs +2 -3
- package/dist/utils/index.d.mts +4 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/{utils-NloIXYE0.mjs → utils-s65Fz0OM.mjs} +5 -1
- package/package.json +1 -1
- package/src/error/codes.ts +21 -0
- package/src/error/index.ts +26 -1
- package/src/social-providers/apple.ts +2 -1
- package/src/social-providers/cognito.ts +1 -2
- package/src/social-providers/google.ts +1 -2
- package/src/types/init-options.ts +9 -1
- package/src/types/plugin-client.ts +10 -0
- package/src/types/plugin.ts +1 -1
- package/src/utils/error-codes.ts +16 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/core@1.
|
|
2
|
+
> @better-auth/core@1.5.0-beta.1 build /home/runner/work/better-auth/better-auth/packages/core
|
|
3
3
|
> tsdown
|
|
4
4
|
|
|
5
5
|
[34mℹ[39m tsdown [2mv0.17.2[22m powered by rolldown [2mv1.0.0-beta.53[22m
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[34mℹ[39m entry: [34msrc/index.ts, src/db/index.ts, src/db/adapter/index.ts, src/async_hooks/index.ts, src/async_hooks/pure.index.ts, src/context/index.ts, src/env/index.ts, src/oauth2/index.ts, src/api/index.ts, src/social-providers/index.ts, src/utils/index.ts, src/error/index.ts[39m
|
|
8
8
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
9
9
|
[34mℹ[39m Build start
|
|
10
|
-
[34mℹ[39m [2mdist/[22m[1msocial-providers/index.mjs[22m [2m 80.
|
|
10
|
+
[34mℹ[39m [2mdist/[22m[1msocial-providers/index.mjs[22m [2m 80.94 kB[22m [2m│ gzip: 10.43 kB[22m
|
|
11
11
|
[34mℹ[39m [2mdist/[22m[1mdb/adapter/index.mjs[22m [2m 38.55 kB[22m [2m│ gzip: 7.86 kB[22m
|
|
12
12
|
[34mℹ[39m [2mdist/[22m[1mdb/index.mjs[22m [2m 1.66 kB[22m [2m│ gzip: 0.54 kB[22m
|
|
13
13
|
[34mℹ[39m [2mdist/[22m[1mapi/index.mjs[22m [2m 1.23 kB[22m [2m│ gzip: 0.48 kB[22m
|
|
@@ -17,19 +17,19 @@
|
|
|
17
17
|
[34mℹ[39m [2mdist/[22m[1mcontext/index.mjs[22m [2m 0.70 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
18
18
|
[34mℹ[39m [2mdist/[22m[1menv/index.mjs[22m [2m 0.44 kB[22m [2m│ gzip: 0.25 kB[22m
|
|
19
19
|
[34mℹ[39m [2mdist/[22m[1mutils/index.mjs[22m [2m 0.24 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
20
|
-
[34mℹ[39m [2mdist/[22m[1merror/index.mjs[22m [2m 0.
|
|
20
|
+
[34mℹ[39m [2mdist/[22m[1merror/index.mjs[22m [2m 0.22 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
21
21
|
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m 0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
22
22
|
[34mℹ[39m [2mdist/[22moauth2-BjWM15hm.mjs [2m 12.82 kB[22m [2m│ gzip: 3.16 kB[22m
|
|
23
23
|
[34mℹ[39m [2mdist/[22menv-DbssmzoK.mjs [2m 7.67 kB[22m [2m│ gzip: 2.54 kB[22m
|
|
24
24
|
[34mℹ[39m [2mdist/[22mget-tables-CMc_Emww.mjs [2m 6.76 kB[22m [2m│ gzip: 1.30 kB[22m
|
|
25
25
|
[34mℹ[39m [2mdist/[22mcontext-DblZrIwO.mjs [2m 3.89 kB[22m [2m│ gzip: 1.00 kB[22m
|
|
26
|
-
[34mℹ[39m [2mdist/[22merror-
|
|
27
|
-
[34mℹ[39m [2mdist/[22mutils-
|
|
26
|
+
[34mℹ[39m [2mdist/[22merror-Dj5gH2lv.mjs [2m 3.07 kB[22m [2m│ gzip: 1.23 kB[22m
|
|
27
|
+
[34mℹ[39m [2mdist/[22mutils-s65Fz0OM.mjs [2m 1.22 kB[22m [2m│ gzip: 0.61 kB[22m
|
|
28
|
+
[34mℹ[39m [2mdist/[22m[32m[1merror/index.d.mts[22m[39m [2m 5.91 kB[22m [2m│ gzip: 1.42 kB[22m
|
|
28
29
|
[34mℹ[39m [2mdist/[22m[32m[1msocial-providers/index.d.mts[22m[39m [2m 3.88 kB[22m [2m│ gzip: 1.19 kB[22m
|
|
29
30
|
[34mℹ[39m [2mdist/[22m[32m[1mcontext/index.d.mts[22m[39m [2m 3.02 kB[22m [2m│ gzip: 0.96 kB[22m
|
|
30
|
-
[34mℹ[39m [2mdist/[22m[32m[1merror/index.d.mts[22m[39m [2m 1.84 kB[22m [2m│ gzip: 0.72 kB[22m
|
|
31
31
|
[34mℹ[39m [2mdist/[22m[32m[1mdb/adapter/index.d.mts[22m[39m [2m 1.34 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
32
|
-
[34mℹ[39m [2mdist/[22m[32m[1mutils/index.d.mts[22m[39m [2m 1.
|
|
32
|
+
[34mℹ[39m [2mdist/[22m[32m[1mutils/index.d.mts[22m[39m [2m 1.24 kB[22m [2m│ gzip: 0.56 kB[22m
|
|
33
33
|
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 0.92 kB[22m [2m│ gzip: 0.36 kB[22m
|
|
34
34
|
[34mℹ[39m [2mdist/[22m[32m[1moauth2/index.d.mts[22m[39m [2m 0.88 kB[22m [2m│ gzip: 0.32 kB[22m
|
|
35
35
|
[34mℹ[39m [2mdist/[22m[32m[1mdb/index.d.mts[22m[39m [2m 0.81 kB[22m [2m│ gzip: 0.34 kB[22m
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
[34mℹ[39m [2mdist/[22m[32m[1mapi/index.d.mts[22m[39m [2m 0.26 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
38
38
|
[34mℹ[39m [2mdist/[22m[32m[1masync_hooks/index.d.mts[22m[39m [2m 0.24 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
39
39
|
[34mℹ[39m [2mdist/[22m[32m[1masync_hooks/pure.index.d.mts[22m[39m [2m 0.22 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
40
|
-
[34mℹ[39m [2mdist/[22m[32mindex-
|
|
40
|
+
[34mℹ[39m [2mdist/[22m[32mindex-oZTwg35a.d.mts[39m [2m221.64 kB[22m [2m│ gzip: 35.40 kB[22m
|
|
41
41
|
[34mℹ[39m [2mdist/[22m[32mindex-BRBu0-5h.d.mts[39m [2m 3.31 kB[22m [2m│ gzip: 1.11 kB[22m
|
|
42
|
-
[34mℹ[39m 32 files, total:
|
|
43
|
-
[32m✔[39m Build complete in [
|
|
42
|
+
[34mℹ[39m 32 files, total: 406.48 kB
|
|
43
|
+
[32m✔[39m Build complete in [32m4859ms[39m
|
package/dist/api/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-
|
|
1
|
+
import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-oZTwg35a.mjs";
|
|
2
2
|
export { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
|
package/dist/context/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Yn as DBAdapter, er as DBTransactionAdapter, f as AuthContext } from "../index-
|
|
1
|
+
import { Yn as DBAdapter, er as DBTransactionAdapter, f as AuthContext } from "../index-oZTwg35a.mjs";
|
|
2
2
|
import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
3
3
|
import { EndpointContext, InputContext } from "better-call";
|
|
4
4
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $n as DBAdapterSchemaCreation, Cr as initGetFieldName, Er as initGetDefaultFieldName, Jn as CustomAdapter, Qn as DBAdapterInstance, Sr as initGetIdField, Tr as initGetDefaultModelName, Xn as DBAdapterDebugLogOption, Yn as DBAdapter, Zn as DBAdapterFactoryConfig, ar as withApplyDefault, cr as createAdapterFactory, dr as AdapterFactoryCustomizeAdapterCreator, er as DBTransactionAdapter, fr as AdapterFactoryOptions, hr as CreateCustomAdapter, ir as deepmerge, lr as AdapterConfig, mr as CreateAdapterOptions, nr as JoinOption, or as AdapterFactory, pr as AdapterTestDebugLogs, qn as CleanedWhere, rr as Where, sr as createAdapter, tr as JoinConfig, ur as AdapterFactoryConfig, wr as initGetFieldAttributes, xr as initGetModelName } from "../../index-
|
|
1
|
+
import { $n as DBAdapterSchemaCreation, Cr as initGetFieldName, Er as initGetDefaultFieldName, Jn as CustomAdapter, Qn as DBAdapterInstance, Sr as initGetIdField, Tr as initGetDefaultModelName, Xn as DBAdapterDebugLogOption, Yn as DBAdapter, Zn as DBAdapterFactoryConfig, ar as withApplyDefault, cr as createAdapterFactory, dr as AdapterFactoryCustomizeAdapterCreator, er as DBTransactionAdapter, fr as AdapterFactoryOptions, hr as CreateCustomAdapter, ir as deepmerge, lr as AdapterConfig, mr as CreateAdapterOptions, nr as JoinOption, or as AdapterFactory, pr as AdapterTestDebugLogs, qn as CleanedWhere, rr as Where, sr as createAdapter, tr as JoinConfig, ur as AdapterFactoryConfig, wr as initGetFieldAttributes, xr as initGetModelName } from "../../index-oZTwg35a.mjs";
|
|
2
2
|
export { AdapterConfig, AdapterFactory, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, JoinOption, Where, createAdapter, createAdapterFactory, deepmerge, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName, withApplyDefault };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as getAuthTables } from "../../get-tables-CMc_Emww.mjs";
|
|
2
2
|
import { i as logger, n as createLogger, o as getColorDepth, t as TTY_COLORS } from "../../env-DbssmzoK.mjs";
|
|
3
|
-
import { n as safeJSONParse, r as generateId } from "../../utils-
|
|
4
|
-
import {
|
|
3
|
+
import { n as safeJSONParse, r as generateId } from "../../utils-s65Fz0OM.mjs";
|
|
4
|
+
import { n as BetterAuthError } from "../../error-Dj5gH2lv.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/db/adapter/get-default-model-name.ts
|
|
7
7
|
const initGetDefaultModelName = ({ usePlural, schema }) => {
|
package/dist/db/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Ar as userSchema, Br as BaseModelNames, Dr as Verification, Fr as rateLimitSchema, Gr as DBPrimitive, Hr as DBFieldAttribute, Ir as Account, Kr as ModelNames, Lr as accountSchema, Mr as Session, Nr as sessionSchema, Or as verificationSchema, Pr as RateLimit, Rr as BetterAuthPluginDBSchema, Ur as DBFieldAttributeConfig, Vr as BetterAuthDBSchema, Wr as DBFieldType, jr as coreSchema, kr as User, qr as SecondaryStorage, zr as getAuthTables } from "../index-
|
|
1
|
+
import { Ar as userSchema, Br as BaseModelNames, Dr as Verification, Fr as rateLimitSchema, Gr as DBPrimitive, Hr as DBFieldAttribute, Ir as Account, Kr as ModelNames, Lr as accountSchema, Mr as Session, Nr as sessionSchema, Or as verificationSchema, Pr as RateLimit, Rr as BetterAuthPluginDBSchema, Ur as DBFieldAttributeConfig, Vr as BetterAuthDBSchema, Wr as DBFieldType, jr as coreSchema, kr as User, qr as SecondaryStorage, zr as getAuthTables } from "../index-oZTwg35a.mjs";
|
|
2
2
|
export { Account, BaseModelNames, BetterAuthDBSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, ModelNames, RateLimit, SecondaryStorage, Session, User, Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
|
package/dist/error/index.d.mts
CHANGED
|
@@ -1,35 +1,197 @@
|
|
|
1
|
+
import { APIError as APIError$1 } from "better-call/error";
|
|
2
|
+
|
|
1
3
|
//#region src/error/codes.d.ts
|
|
2
4
|
declare const BASE_ERROR_CODES: {
|
|
3
|
-
readonly USER_NOT_FOUND:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
readonly
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
readonly
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
readonly
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
readonly
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
readonly
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly
|
|
5
|
+
readonly USER_NOT_FOUND: {
|
|
6
|
+
code: "USER_NOT_FOUND";
|
|
7
|
+
message: "User not found";
|
|
8
|
+
};
|
|
9
|
+
readonly FAILED_TO_CREATE_USER: {
|
|
10
|
+
code: "FAILED_TO_CREATE_USER";
|
|
11
|
+
message: "Failed to create user";
|
|
12
|
+
};
|
|
13
|
+
readonly FAILED_TO_CREATE_SESSION: {
|
|
14
|
+
code: "FAILED_TO_CREATE_SESSION";
|
|
15
|
+
message: "Failed to create session";
|
|
16
|
+
};
|
|
17
|
+
readonly FAILED_TO_UPDATE_USER: {
|
|
18
|
+
code: "FAILED_TO_UPDATE_USER";
|
|
19
|
+
message: "Failed to update user";
|
|
20
|
+
};
|
|
21
|
+
readonly FAILED_TO_GET_SESSION: {
|
|
22
|
+
code: "FAILED_TO_GET_SESSION";
|
|
23
|
+
message: "Failed to get session";
|
|
24
|
+
};
|
|
25
|
+
readonly INVALID_PASSWORD: {
|
|
26
|
+
code: "INVALID_PASSWORD";
|
|
27
|
+
message: "Invalid password";
|
|
28
|
+
};
|
|
29
|
+
readonly INVALID_EMAIL: {
|
|
30
|
+
code: "INVALID_EMAIL";
|
|
31
|
+
message: "Invalid email";
|
|
32
|
+
};
|
|
33
|
+
readonly INVALID_EMAIL_OR_PASSWORD: {
|
|
34
|
+
code: "INVALID_EMAIL_OR_PASSWORD";
|
|
35
|
+
message: "Invalid email or password";
|
|
36
|
+
};
|
|
37
|
+
readonly INVALID_USER: {
|
|
38
|
+
code: "INVALID_USER";
|
|
39
|
+
message: "Invalid user";
|
|
40
|
+
};
|
|
41
|
+
readonly SOCIAL_ACCOUNT_ALREADY_LINKED: {
|
|
42
|
+
code: "SOCIAL_ACCOUNT_ALREADY_LINKED";
|
|
43
|
+
message: "Social account already linked";
|
|
44
|
+
};
|
|
45
|
+
readonly PROVIDER_NOT_FOUND: {
|
|
46
|
+
code: "PROVIDER_NOT_FOUND";
|
|
47
|
+
message: "Provider not found";
|
|
48
|
+
};
|
|
49
|
+
readonly INVALID_TOKEN: {
|
|
50
|
+
code: "INVALID_TOKEN";
|
|
51
|
+
message: "Invalid token";
|
|
52
|
+
};
|
|
53
|
+
readonly TOKEN_EXPIRED: {
|
|
54
|
+
code: "TOKEN_EXPIRED";
|
|
55
|
+
message: "Token expired";
|
|
56
|
+
};
|
|
57
|
+
readonly ID_TOKEN_NOT_SUPPORTED: {
|
|
58
|
+
code: "ID_TOKEN_NOT_SUPPORTED";
|
|
59
|
+
message: "id_token not supported";
|
|
60
|
+
};
|
|
61
|
+
readonly FAILED_TO_GET_USER_INFO: {
|
|
62
|
+
code: "FAILED_TO_GET_USER_INFO";
|
|
63
|
+
message: "Failed to get user info";
|
|
64
|
+
};
|
|
65
|
+
readonly USER_EMAIL_NOT_FOUND: {
|
|
66
|
+
code: "USER_EMAIL_NOT_FOUND";
|
|
67
|
+
message: "User email not found";
|
|
68
|
+
};
|
|
69
|
+
readonly EMAIL_NOT_VERIFIED: {
|
|
70
|
+
code: "EMAIL_NOT_VERIFIED";
|
|
71
|
+
message: "Email not verified";
|
|
72
|
+
};
|
|
73
|
+
readonly PASSWORD_TOO_SHORT: {
|
|
74
|
+
code: "PASSWORD_TOO_SHORT";
|
|
75
|
+
message: "Password too short";
|
|
76
|
+
};
|
|
77
|
+
readonly PASSWORD_TOO_LONG: {
|
|
78
|
+
code: "PASSWORD_TOO_LONG";
|
|
79
|
+
message: "Password too long";
|
|
80
|
+
};
|
|
81
|
+
readonly USER_ALREADY_EXISTS: {
|
|
82
|
+
code: "USER_ALREADY_EXISTS";
|
|
83
|
+
message: "User already exists.";
|
|
84
|
+
};
|
|
85
|
+
readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: {
|
|
86
|
+
code: "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL";
|
|
87
|
+
message: "User already exists. Use another email.";
|
|
88
|
+
};
|
|
89
|
+
readonly EMAIL_CAN_NOT_BE_UPDATED: {
|
|
90
|
+
code: "EMAIL_CAN_NOT_BE_UPDATED";
|
|
91
|
+
message: "Email can not be updated";
|
|
92
|
+
};
|
|
93
|
+
readonly CREDENTIAL_ACCOUNT_NOT_FOUND: {
|
|
94
|
+
code: "CREDENTIAL_ACCOUNT_NOT_FOUND";
|
|
95
|
+
message: "Credential account not found";
|
|
96
|
+
};
|
|
97
|
+
readonly SESSION_EXPIRED: {
|
|
98
|
+
code: "SESSION_EXPIRED";
|
|
99
|
+
message: "Session expired. Re-authenticate to perform this action.";
|
|
100
|
+
};
|
|
101
|
+
readonly FAILED_TO_UNLINK_LAST_ACCOUNT: {
|
|
102
|
+
code: "FAILED_TO_UNLINK_LAST_ACCOUNT";
|
|
103
|
+
message: "You can't unlink your last account";
|
|
104
|
+
};
|
|
105
|
+
readonly ACCOUNT_NOT_FOUND: {
|
|
106
|
+
code: "ACCOUNT_NOT_FOUND";
|
|
107
|
+
message: "Account not found";
|
|
108
|
+
};
|
|
109
|
+
readonly USER_ALREADY_HAS_PASSWORD: {
|
|
110
|
+
code: "USER_ALREADY_HAS_PASSWORD";
|
|
111
|
+
message: "User already has a password. Provide that to delete the account.";
|
|
112
|
+
};
|
|
113
|
+
readonly VERIFICATION_EMAIL_NOT_ENABLED: {
|
|
114
|
+
code: "VERIFICATION_EMAIL_NOT_ENABLED";
|
|
115
|
+
message: "Verification email isn't enabled";
|
|
116
|
+
};
|
|
117
|
+
readonly EMAIL_ALREADY_VERIFIED: {
|
|
118
|
+
code: "EMAIL_ALREADY_VERIFIED";
|
|
119
|
+
message: "Email is already verified";
|
|
120
|
+
};
|
|
121
|
+
readonly EMAIL_MISMATCH: {
|
|
122
|
+
code: "EMAIL_MISMATCH";
|
|
123
|
+
message: "Email mismatch";
|
|
124
|
+
};
|
|
125
|
+
readonly SESSION_NOT_FRESH: {
|
|
126
|
+
code: "SESSION_NOT_FRESH";
|
|
127
|
+
message: "Session is not fresh";
|
|
128
|
+
};
|
|
129
|
+
readonly LINKED_ACCOUNT_ALREADY_EXISTS: {
|
|
130
|
+
code: "LINKED_ACCOUNT_ALREADY_EXISTS";
|
|
131
|
+
message: "Linked account already exists";
|
|
132
|
+
};
|
|
133
|
+
readonly INVALID_ORIGIN: {
|
|
134
|
+
code: "INVALID_ORIGIN";
|
|
135
|
+
message: "Invalid origin";
|
|
136
|
+
};
|
|
137
|
+
readonly INVALID_CALLBACK_URL: {
|
|
138
|
+
code: "INVALID_CALLBACK_URL";
|
|
139
|
+
message: "Invalid callbackURL";
|
|
140
|
+
};
|
|
141
|
+
readonly INVALID_REDIRECT_URL: {
|
|
142
|
+
code: "INVALID_REDIRECT_URL";
|
|
143
|
+
message: "Invalid redirectURL";
|
|
144
|
+
};
|
|
145
|
+
readonly INVALID_ERROR_CALLBACK_URL: {
|
|
146
|
+
code: "INVALID_ERROR_CALLBACK_URL";
|
|
147
|
+
message: "Invalid errorCallbackURL";
|
|
148
|
+
};
|
|
149
|
+
readonly INVALID_NEW_USER_CALLBACK_URL: {
|
|
150
|
+
code: "INVALID_NEW_USER_CALLBACK_URL";
|
|
151
|
+
message: "Invalid newUserCallbackURL";
|
|
152
|
+
};
|
|
153
|
+
readonly MISSING_OR_NULL_ORIGIN: {
|
|
154
|
+
code: "MISSING_OR_NULL_ORIGIN";
|
|
155
|
+
message: "Missing or null Origin";
|
|
156
|
+
};
|
|
157
|
+
readonly CALLBACK_URL_REQUIRED: {
|
|
158
|
+
code: "CALLBACK_URL_REQUIRED";
|
|
159
|
+
message: "callbackURL is required";
|
|
160
|
+
};
|
|
161
|
+
readonly FAILED_TO_CREATE_VERIFICATION: {
|
|
162
|
+
code: "FAILED_TO_CREATE_VERIFICATION";
|
|
163
|
+
message: "Unable to create verification";
|
|
164
|
+
};
|
|
165
|
+
readonly FIELD_NOT_ALLOWED: {
|
|
166
|
+
code: "FIELD_NOT_ALLOWED";
|
|
167
|
+
message: "Field not allowed to be set";
|
|
168
|
+
};
|
|
169
|
+
readonly ASYNC_VALIDATION_NOT_SUPPORTED: {
|
|
170
|
+
code: "ASYNC_VALIDATION_NOT_SUPPORTED";
|
|
171
|
+
message: "Async validation is not supported";
|
|
172
|
+
};
|
|
173
|
+
readonly VALIDATION_ERROR: {
|
|
174
|
+
code: "VALIDATION_ERROR";
|
|
175
|
+
message: "Validation Error";
|
|
176
|
+
};
|
|
177
|
+
readonly MISSING_FIELD: {
|
|
178
|
+
code: "MISSING_FIELD";
|
|
179
|
+
message: "Field is required";
|
|
180
|
+
};
|
|
28
181
|
};
|
|
182
|
+
type APIErrorCode = keyof typeof BASE_ERROR_CODES;
|
|
29
183
|
//#endregion
|
|
30
184
|
//#region src/error/index.d.ts
|
|
31
185
|
declare class BetterAuthError extends Error {
|
|
32
186
|
constructor(message: string, cause?: string | undefined);
|
|
33
187
|
}
|
|
188
|
+
declare class APIError extends APIError$1 {
|
|
189
|
+
constructor(...args: ConstructorParameters<typeof APIError$1>);
|
|
190
|
+
static fromStatus(status: ConstructorParameters<typeof APIError$1>[0], body?: ConstructorParameters<typeof APIError$1>[1]): APIError;
|
|
191
|
+
static from(status: ConstructorParameters<typeof APIError$1>[0], error: {
|
|
192
|
+
code: string;
|
|
193
|
+
message: string;
|
|
194
|
+
}): APIError;
|
|
195
|
+
}
|
|
34
196
|
//#endregion
|
|
35
|
-
export { BASE_ERROR_CODES, BetterAuthError };
|
|
197
|
+
export { APIError, type APIErrorCode, BASE_ERROR_CODES, BetterAuthError };
|
package/dist/error/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../env-DbssmzoK.mjs";
|
|
2
|
-
import "../utils-
|
|
3
|
-
import { n as BASE_ERROR_CODES, t as
|
|
2
|
+
import "../utils-s65Fz0OM.mjs";
|
|
3
|
+
import { n as BetterAuthError, r as BASE_ERROR_CODES, t as APIError } from "../error-Dj5gH2lv.mjs";
|
|
4
4
|
|
|
5
|
-
export { BASE_ERROR_CODES, BetterAuthError };
|
|
5
|
+
export { APIError, BASE_ERROR_CODES, BetterAuthError };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { i as defineErrorCodes } from "./utils-
|
|
1
|
+
import { i as defineErrorCodes } from "./utils-s65Fz0OM.mjs";
|
|
2
|
+
import { APIError } from "better-call/error";
|
|
2
3
|
|
|
3
4
|
//#region src/error/codes.ts
|
|
4
5
|
const BASE_ERROR_CODES = defineErrorCodes({
|
|
@@ -10,9 +11,11 @@ const BASE_ERROR_CODES = defineErrorCodes({
|
|
|
10
11
|
INVALID_PASSWORD: "Invalid password",
|
|
11
12
|
INVALID_EMAIL: "Invalid email",
|
|
12
13
|
INVALID_EMAIL_OR_PASSWORD: "Invalid email or password",
|
|
14
|
+
INVALID_USER: "Invalid user",
|
|
13
15
|
SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked",
|
|
14
16
|
PROVIDER_NOT_FOUND: "Provider not found",
|
|
15
17
|
INVALID_TOKEN: "Invalid token",
|
|
18
|
+
TOKEN_EXPIRED: "Token expired",
|
|
16
19
|
ID_TOKEN_NOT_SUPPORTED: "id_token not supported",
|
|
17
20
|
FAILED_TO_GET_USER_INFO: "Failed to get user info",
|
|
18
21
|
USER_EMAIL_NOT_FOUND: "User email not found",
|
|
@@ -26,7 +29,24 @@ const BASE_ERROR_CODES = defineErrorCodes({
|
|
|
26
29
|
SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.",
|
|
27
30
|
FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account",
|
|
28
31
|
ACCOUNT_NOT_FOUND: "Account not found",
|
|
29
|
-
USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account."
|
|
32
|
+
USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.",
|
|
33
|
+
VERIFICATION_EMAIL_NOT_ENABLED: "Verification email isn't enabled",
|
|
34
|
+
EMAIL_ALREADY_VERIFIED: "Email is already verified",
|
|
35
|
+
EMAIL_MISMATCH: "Email mismatch",
|
|
36
|
+
SESSION_NOT_FRESH: "Session is not fresh",
|
|
37
|
+
LINKED_ACCOUNT_ALREADY_EXISTS: "Linked account already exists",
|
|
38
|
+
INVALID_ORIGIN: "Invalid origin",
|
|
39
|
+
INVALID_CALLBACK_URL: "Invalid callbackURL",
|
|
40
|
+
INVALID_REDIRECT_URL: "Invalid redirectURL",
|
|
41
|
+
INVALID_ERROR_CALLBACK_URL: "Invalid errorCallbackURL",
|
|
42
|
+
INVALID_NEW_USER_CALLBACK_URL: "Invalid newUserCallbackURL",
|
|
43
|
+
MISSING_OR_NULL_ORIGIN: "Missing or null Origin",
|
|
44
|
+
CALLBACK_URL_REQUIRED: "callbackURL is required",
|
|
45
|
+
FAILED_TO_CREATE_VERIFICATION: "Unable to create verification",
|
|
46
|
+
FIELD_NOT_ALLOWED: "Field not allowed to be set",
|
|
47
|
+
ASYNC_VALIDATION_NOT_SUPPORTED: "Async validation is not supported",
|
|
48
|
+
VALIDATION_ERROR: "Validation Error",
|
|
49
|
+
MISSING_FIELD: "Field is required"
|
|
30
50
|
});
|
|
31
51
|
|
|
32
52
|
//#endregion
|
|
@@ -40,6 +60,20 @@ var BetterAuthError = class extends Error {
|
|
|
40
60
|
this.stack = "";
|
|
41
61
|
}
|
|
42
62
|
};
|
|
63
|
+
var APIError$1 = class APIError$1 extends APIError {
|
|
64
|
+
constructor(...args) {
|
|
65
|
+
super(...args);
|
|
66
|
+
}
|
|
67
|
+
static fromStatus(status, body) {
|
|
68
|
+
return new APIError$1(status, body);
|
|
69
|
+
}
|
|
70
|
+
static from(status, error) {
|
|
71
|
+
return new APIError$1(status, {
|
|
72
|
+
message: error.message,
|
|
73
|
+
code: error.code
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
43
77
|
|
|
44
78
|
//#endregion
|
|
45
|
-
export {
|
|
79
|
+
export { BetterAuthError as n, BASE_ERROR_CODES as r, APIError$1 as t };
|
|
@@ -6288,7 +6288,10 @@ type BetterAuthPlugin = {
|
|
|
6288
6288
|
/**
|
|
6289
6289
|
* The error codes returned by the plugin
|
|
6290
6290
|
*/
|
|
6291
|
-
$ERROR_CODES?: Record<string,
|
|
6291
|
+
$ERROR_CODES?: Record<string, {
|
|
6292
|
+
code: string;
|
|
6293
|
+
message: string;
|
|
6294
|
+
}> | undefined;
|
|
6292
6295
|
/**
|
|
6293
6296
|
* All database operations that are performed by the plugin
|
|
6294
6297
|
*
|
|
@@ -7188,8 +7191,16 @@ type BetterAuthOptions = {
|
|
|
7188
7191
|
} | undefined;
|
|
7189
7192
|
/**
|
|
7190
7193
|
* List of trusted origins.
|
|
7194
|
+
*
|
|
7195
|
+
* @param request - The request object.
|
|
7196
|
+
* It'll be undefined if no request was
|
|
7197
|
+
* made. Like during a create context call
|
|
7198
|
+
* or `auth.api` call.
|
|
7199
|
+
*
|
|
7200
|
+
* Trusted origins will be dynamically
|
|
7201
|
+
* calculated based on the request.
|
|
7191
7202
|
*/
|
|
7192
|
-
trustedOrigins?: (string[] | ((request
|
|
7203
|
+
trustedOrigins?: (string[] | ((request?: Request | undefined) => Awaitable<string[]>)) | undefined;
|
|
7193
7204
|
/**
|
|
7194
7205
|
* Rate limiting configuration
|
|
7195
7206
|
*/
|
|
@@ -7792,6 +7803,13 @@ interface BetterAuthClientPlugin {
|
|
|
7792
7803
|
* plugin or any plugin the user might have added.
|
|
7793
7804
|
*/
|
|
7794
7805
|
atomListeners?: ClientAtomListener[] | undefined;
|
|
7806
|
+
/**
|
|
7807
|
+
* The error codes returned by the plugin
|
|
7808
|
+
*/
|
|
7809
|
+
$ERROR_CODES?: Record<string, {
|
|
7810
|
+
code: string;
|
|
7811
|
+
message: string;
|
|
7812
|
+
}>;
|
|
7795
7813
|
}
|
|
7796
7814
|
//#endregion
|
|
7797
7815
|
//#region src/api/index.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as BetterAuthRateLimitOptions, _r as LiteralString, b as HookEndpointContext, br as Primitive, c as BetterAuthClientPlugin, d as ClientStore, f as AuthContext, g as BetterAuthOptions, gr as Awaitable, h as BetterAuthAdvancedOptions, kn as BetterAuthCookies, l as ClientAtomListener, m as InternalAdapter, o as StandardSchemaV1, p as GenericEndpointContext, s as BetterAuthClientOptions, u as ClientFetchOption, v as GenerateIdFn, vr as LiteralUnion, y as BetterAuthPlugin, yr as Prettify } from "./index-
|
|
1
|
+
import { _ as BetterAuthRateLimitOptions, _r as LiteralString, b as HookEndpointContext, br as Primitive, c as BetterAuthClientPlugin, d as ClientStore, f as AuthContext, g as BetterAuthOptions, gr as Awaitable, h as BetterAuthAdvancedOptions, kn as BetterAuthCookies, l as ClientAtomListener, m as InternalAdapter, o as StandardSchemaV1, p as GenericEndpointContext, s as BetterAuthClientOptions, u as ClientFetchOption, v as GenerateIdFn, vr as LiteralUnion, y as BetterAuthPlugin, yr as Prettify } from "./index-oZTwg35a.mjs";
|
|
2
2
|
export { AuthContext, Awaitable, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientFetchOption, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InternalAdapter, LiteralString, LiteralUnion, Prettify, Primitive, StandardSchemaV1 };
|
package/dist/oauth2/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { An as getJwks, Bn as createAuthorizationURL, Fn as validateToken, Gn as OAuthProvider, Hn as createClientCredentialsTokenRequest, In as generateCodeChallenge, Kn as ProviderOptions, Ln as getOAuth2Tokens, Mn as verifyJwsAccessToken, Nn as createAuthorizationCodeRequest, Pn as validateAuthorizationCode, Rn as createRefreshAccessTokenRequest, Un as OAuth2Tokens, Vn as clientCredentialsToken, Wn as OAuth2UserInfo, jn as verifyAccessToken, zn as refreshAccessToken } from "../index-
|
|
1
|
+
import { An as getJwks, Bn as createAuthorizationURL, Fn as validateToken, Gn as OAuthProvider, Hn as createClientCredentialsTokenRequest, In as generateCodeChallenge, Kn as ProviderOptions, Ln as getOAuth2Tokens, Mn as verifyJwsAccessToken, Nn as createAuthorizationCodeRequest, Pn as validateAuthorizationCode, Rn as createRefreshAccessTokenRequest, Un as OAuth2Tokens, Vn as clientCredentialsToken, Wn as OAuth2UserInfo, jn as verifyAccessToken, zn as refreshAccessToken } from "../index-oZTwg35a.mjs";
|
|
2
2
|
export { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions, clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getJwks, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken, verifyAccessToken, verifyJwsAccessToken };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as AccountStatus, $t as GoogleProfile, A as PolarOptions, At as linear, B as LineIdTokenPayload, Bt as TwitchOptions, C as SocialProviderListEnum, Cn as atlassian, Ct as gitlab, D as VercelOptions, Dn as apple, Dt as LinearOptions, E as socialProviders, En as AppleProfile, Et as linkedin, F as PayPalTokenResponse, Ft as DropboxProfile, G as NaverProfile, Gt as spotify, H as LineUserInfo, Ht as twitch, I as paypal, It as dropbox, J as KakaoProfile, Jt as slack, K as naver, Kt as SlackOptions, L as PaybinOptions, Lt as TwitterOption, M as polar, Mt as KickProfile, N as PayPalOptions, Nt as kick, O as VercelProfile, On as getApplePublicKey, Ot as LinearProfile, P as PayPalProfile, Pt as DropboxOptions, Q as notion, Qt as GoogleOptions, R as PaybinProfile, Rt as TwitterProfile, S as SocialProviderList, Sn as AtlassianProfile, St as GitlabProfile, T as socialProviderList, Tn as AppleOptions, Tt as LinkedInProfile, U as line, Ut as SpotifyOptions, V as LineOptions, Vt as TwitchProfile, W as NaverOptions, Wt as SpotifyProfile, X as NotionOptions, Xt as HuggingFaceProfile, Y as kakao, Yt as HuggingFaceOptions, Z as NotionProfile, Zt as huggingface, _n as CognitoOptions, _t as reddit, an as GithubOptions, at as zoom, bn as getCognitoPublicKey, bt as tiktok, cn as FigmaOptions, ct as vk, dn as FacebookOptions, dt as salesforce, en as getGooglePublicKey, et as LoginType, fn as FacebookProfile, ft as RobloxOptions, gn as discord, gt as RedditProfile, hn as DiscordProfile, ht as RedditOptions, in as microsoft, it as ZoomProfile, j as PolarProfile, jt as KickOptions, k as vercel, kt as LinearUser, ln as FigmaProfile, lt as SalesforceOptions, mn as DiscordOptions, mt as roblox, nn as MicrosoftEntraIDProfile, nt as PronounOption, on as GithubProfile, ot as VkOption, pn as facebook, pt as RobloxProfile, q as KakaoOptions, qt as SlackProfile, rn as MicrosoftOptions, rt as ZoomOptions, sn as github, st as VkProfile, tn as google, tt as PhoneNumber, un as figma, ut as SalesforceProfile, vn as CognitoProfile, vt as TiktokOptions, w as SocialProviders, wn as AppleNonConformUser, wt as LinkedInOptions, x as SocialProvider, xn as AtlassianOptions, xt as GitlabOptions, yn as cognito, yt as TiktokProfile, z as paybin, zt as twitter } from "../index-
|
|
1
|
+
import { $ as AccountStatus, $t as GoogleProfile, A as PolarOptions, At as linear, B as LineIdTokenPayload, Bt as TwitchOptions, C as SocialProviderListEnum, Cn as atlassian, Ct as gitlab, D as VercelOptions, Dn as apple, Dt as LinearOptions, E as socialProviders, En as AppleProfile, Et as linkedin, F as PayPalTokenResponse, Ft as DropboxProfile, G as NaverProfile, Gt as spotify, H as LineUserInfo, Ht as twitch, I as paypal, It as dropbox, J as KakaoProfile, Jt as slack, K as naver, Kt as SlackOptions, L as PaybinOptions, Lt as TwitterOption, M as polar, Mt as KickProfile, N as PayPalOptions, Nt as kick, O as VercelProfile, On as getApplePublicKey, Ot as LinearProfile, P as PayPalProfile, Pt as DropboxOptions, Q as notion, Qt as GoogleOptions, R as PaybinProfile, Rt as TwitterProfile, S as SocialProviderList, Sn as AtlassianProfile, St as GitlabProfile, T as socialProviderList, Tn as AppleOptions, Tt as LinkedInProfile, U as line, Ut as SpotifyOptions, V as LineOptions, Vt as TwitchProfile, W as NaverOptions, Wt as SpotifyProfile, X as NotionOptions, Xt as HuggingFaceProfile, Y as kakao, Yt as HuggingFaceOptions, Z as NotionProfile, Zt as huggingface, _n as CognitoOptions, _t as reddit, an as GithubOptions, at as zoom, bn as getCognitoPublicKey, bt as tiktok, cn as FigmaOptions, ct as vk, dn as FacebookOptions, dt as salesforce, en as getGooglePublicKey, et as LoginType, fn as FacebookProfile, ft as RobloxOptions, gn as discord, gt as RedditProfile, hn as DiscordProfile, ht as RedditOptions, in as microsoft, it as ZoomProfile, j as PolarProfile, jt as KickOptions, k as vercel, kt as LinearUser, ln as FigmaProfile, lt as SalesforceOptions, mn as DiscordOptions, mt as roblox, nn as MicrosoftEntraIDProfile, nt as PronounOption, on as GithubProfile, ot as VkOption, pn as facebook, pt as RobloxProfile, q as KakaoOptions, qt as SlackProfile, rn as MicrosoftOptions, rt as ZoomOptions, sn as github, st as VkProfile, tn as google, tt as PhoneNumber, un as figma, ut as SalesforceProfile, vn as CognitoProfile, vt as TiktokOptions, w as SocialProviders, wn as AppleNonConformUser, wt as LinkedInOptions, x as SocialProvider, xn as AtlassianOptions, xt as GitlabOptions, yn as cognito, yt as TiktokProfile, z as paybin, zt as twitter } from "../index-oZTwg35a.mjs";
|
|
2
2
|
export { AccountStatus, AppleNonConformUser, AppleOptions, AppleProfile, AtlassianOptions, AtlassianProfile, CognitoOptions, CognitoProfile, DiscordOptions, DiscordProfile, DropboxOptions, DropboxProfile, FacebookOptions, FacebookProfile, FigmaOptions, FigmaProfile, GithubOptions, GithubProfile, GitlabOptions, GitlabProfile, GoogleOptions, GoogleProfile, HuggingFaceOptions, HuggingFaceProfile, KakaoOptions, KakaoProfile, KickOptions, KickProfile, LineIdTokenPayload, LineOptions, LineUserInfo, LinearOptions, LinearProfile, LinearUser, LinkedInOptions, LinkedInProfile, LoginType, MicrosoftEntraIDProfile, MicrosoftOptions, NaverOptions, NaverProfile, NotionOptions, NotionProfile, PayPalOptions, PayPalProfile, PayPalTokenResponse, PaybinOptions, PaybinProfile, PhoneNumber, PolarOptions, PolarProfile, PronounOption, RedditOptions, RedditProfile, RobloxOptions, RobloxProfile, SalesforceOptions, SalesforceProfile, SlackOptions, SlackProfile, SocialProvider, SocialProviderList, SocialProviderListEnum, SocialProviders, SpotifyOptions, SpotifyProfile, TiktokOptions, TiktokProfile, TwitchOptions, TwitchProfile, TwitterOption, TwitterProfile, VercelOptions, VercelProfile, VkOption, VkProfile, ZoomOptions, ZoomProfile, apple, atlassian, cognito, discord, dropbox, facebook, figma, getApplePublicKey, getCognitoPublicKey, getGooglePublicKey, github, gitlab, google, huggingface, kakao, kick, line, linear, linkedin, microsoft, naver, notion, paybin, paypal, polar, reddit, roblox, salesforce, slack, socialProviderList, socialProviders, spotify, tiktok, twitch, twitter, vercel, vk, zoom };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { i as logger } from "../env-DbssmzoK.mjs";
|
|
2
|
-
import "../utils-
|
|
3
|
-
import {
|
|
2
|
+
import "../utils-s65Fz0OM.mjs";
|
|
3
|
+
import { n as BetterAuthError, t as APIError } from "../error-Dj5gH2lv.mjs";
|
|
4
4
|
import { a as validateAuthorizationCode, c as refreshAccessToken, d as getOAuth2Tokens, l as createAuthorizationURL, u as generateCodeChallenge } from "../oauth2-BjWM15hm.mjs";
|
|
5
5
|
import * as z from "zod";
|
|
6
6
|
import { base64 } from "@better-auth/utils/base64";
|
|
7
7
|
import { betterFetch } from "@better-fetch/fetch";
|
|
8
8
|
import { createRemoteJWKSet, decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
|
|
9
|
-
import { APIError } from "better-call";
|
|
10
9
|
|
|
11
10
|
//#region src/social-providers/apple.ts
|
|
12
11
|
const apple = (options) => {
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -4,7 +4,10 @@ type SpecialCharacter = "_";
|
|
|
4
4
|
type IsValidUpperSnakeCase<S extends string> = S extends `${infer F}${infer R}` ? F extends UpperLetter | SpecialCharacter ? IsValidUpperSnakeCase<R> : false : true;
|
|
5
5
|
type InvalidKeyError<K$1 extends string> = `Invalid error code key: "${K$1}" - must only contain uppercase letters (A-Z) and underscores (_)`;
|
|
6
6
|
type ValidateErrorCodes<T> = { [K in keyof T]: K extends string ? IsValidUpperSnakeCase<K> extends false ? InvalidKeyError<K> : T[K] : T[K] };
|
|
7
|
-
declare function defineErrorCodes<const T extends Record<string, string>>(codes: ValidateErrorCodes<T>): T
|
|
7
|
+
declare function defineErrorCodes<const T extends Record<string, string>>(codes: ValidateErrorCodes<T>): { [K in keyof T]: {
|
|
8
|
+
code: K;
|
|
9
|
+
message: T[K];
|
|
10
|
+
} };
|
|
8
11
|
//#endregion
|
|
9
12
|
//#region src/utils/id.d.ts
|
|
10
13
|
declare const generateId: (size?: number) => string;
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "../env-DbssmzoK.mjs";
|
|
2
|
-
import { i as defineErrorCodes, n as safeJSONParse, r as generateId, t as capitalizeFirstLetter } from "../utils-
|
|
2
|
+
import { i as defineErrorCodes, n as safeJSONParse, r as generateId, t as capitalizeFirstLetter } from "../utils-s65Fz0OM.mjs";
|
|
3
3
|
|
|
4
4
|
export { capitalizeFirstLetter, defineErrorCodes, generateId, safeJSONParse };
|
|
@@ -3,7 +3,11 @@ import { createRandomStringGenerator } from "@better-auth/utils/random";
|
|
|
3
3
|
|
|
4
4
|
//#region src/utils/error-codes.ts
|
|
5
5
|
function defineErrorCodes(codes) {
|
|
6
|
-
return codes
|
|
6
|
+
return Object.fromEntries(Object.entries(codes).map(([key, value]) => [key, {
|
|
7
|
+
code: key,
|
|
8
|
+
message: value,
|
|
9
|
+
toString: () => value
|
|
10
|
+
}]));
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
//#endregion
|
package/package.json
CHANGED
package/src/error/codes.ts
CHANGED
|
@@ -9,9 +9,11 @@ export const BASE_ERROR_CODES = defineErrorCodes({
|
|
|
9
9
|
INVALID_PASSWORD: "Invalid password",
|
|
10
10
|
INVALID_EMAIL: "Invalid email",
|
|
11
11
|
INVALID_EMAIL_OR_PASSWORD: "Invalid email or password",
|
|
12
|
+
INVALID_USER: "Invalid user",
|
|
12
13
|
SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked",
|
|
13
14
|
PROVIDER_NOT_FOUND: "Provider not found",
|
|
14
15
|
INVALID_TOKEN: "Invalid token",
|
|
16
|
+
TOKEN_EXPIRED: "Token expired",
|
|
15
17
|
ID_TOKEN_NOT_SUPPORTED: "id_token not supported",
|
|
16
18
|
FAILED_TO_GET_USER_INFO: "Failed to get user info",
|
|
17
19
|
USER_EMAIL_NOT_FOUND: "User email not found",
|
|
@@ -28,4 +30,23 @@ export const BASE_ERROR_CODES = defineErrorCodes({
|
|
|
28
30
|
ACCOUNT_NOT_FOUND: "Account not found",
|
|
29
31
|
USER_ALREADY_HAS_PASSWORD:
|
|
30
32
|
"User already has a password. Provide that to delete the account.",
|
|
33
|
+
VERIFICATION_EMAIL_NOT_ENABLED: "Verification email isn't enabled",
|
|
34
|
+
EMAIL_ALREADY_VERIFIED: "Email is already verified",
|
|
35
|
+
EMAIL_MISMATCH: "Email mismatch",
|
|
36
|
+
SESSION_NOT_FRESH: "Session is not fresh",
|
|
37
|
+
LINKED_ACCOUNT_ALREADY_EXISTS: "Linked account already exists",
|
|
38
|
+
INVALID_ORIGIN: "Invalid origin",
|
|
39
|
+
INVALID_CALLBACK_URL: "Invalid callbackURL",
|
|
40
|
+
INVALID_REDIRECT_URL: "Invalid redirectURL",
|
|
41
|
+
INVALID_ERROR_CALLBACK_URL: "Invalid errorCallbackURL",
|
|
42
|
+
INVALID_NEW_USER_CALLBACK_URL: "Invalid newUserCallbackURL",
|
|
43
|
+
MISSING_OR_NULL_ORIGIN: "Missing or null Origin",
|
|
44
|
+
CALLBACK_URL_REQUIRED: "callbackURL is required",
|
|
45
|
+
FAILED_TO_CREATE_VERIFICATION: "Unable to create verification",
|
|
46
|
+
FIELD_NOT_ALLOWED: "Field not allowed to be set",
|
|
47
|
+
ASYNC_VALIDATION_NOT_SUPPORTED: "Async validation is not supported",
|
|
48
|
+
VALIDATION_ERROR: "Validation Error",
|
|
49
|
+
MISSING_FIELD: "Field is required",
|
|
31
50
|
});
|
|
51
|
+
|
|
52
|
+
export type APIErrorCode = keyof typeof BASE_ERROR_CODES;
|
package/src/error/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { APIError as BaseAPIError } from "better-call/error";
|
|
2
|
+
|
|
1
3
|
export class BetterAuthError extends Error {
|
|
2
4
|
constructor(message: string, cause?: string | undefined) {
|
|
3
5
|
super(message);
|
|
@@ -8,4 +10,27 @@ export class BetterAuthError extends Error {
|
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
export { BASE_ERROR_CODES } from "./codes";
|
|
13
|
+
export { type APIErrorCode, BASE_ERROR_CODES } from "./codes";
|
|
14
|
+
|
|
15
|
+
export class APIError extends BaseAPIError {
|
|
16
|
+
constructor(...args: ConstructorParameters<typeof BaseAPIError>) {
|
|
17
|
+
super(...args);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static fromStatus(
|
|
21
|
+
status: ConstructorParameters<typeof BaseAPIError>[0],
|
|
22
|
+
body?: ConstructorParameters<typeof BaseAPIError>[1],
|
|
23
|
+
) {
|
|
24
|
+
return new APIError(status, body);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static from(
|
|
28
|
+
status: ConstructorParameters<typeof BaseAPIError>[0],
|
|
29
|
+
error: { code: string; message: string },
|
|
30
|
+
) {
|
|
31
|
+
return new APIError(status, {
|
|
32
|
+
message: error.message,
|
|
33
|
+
code: error.code,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
|
|
4
|
+
import { APIError } from "../error";
|
|
4
5
|
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
5
6
|
import {
|
|
6
7
|
createAuthorizationURL,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
-
import { APIError } from "better-call";
|
|
3
2
|
import { decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
|
|
4
3
|
import { logger } from "../env";
|
|
5
|
-
import { BetterAuthError } from "../error";
|
|
4
|
+
import { APIError, BetterAuthError } from "../error";
|
|
6
5
|
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
7
6
|
import {
|
|
8
7
|
createAuthorizationURL,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
-
import { APIError } from "better-call";
|
|
3
2
|
import { decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
|
|
4
3
|
import { logger } from "../env";
|
|
5
|
-
import { BetterAuthError } from "../error";
|
|
4
|
+
import { APIError, BetterAuthError } from "../error";
|
|
6
5
|
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
7
6
|
import {
|
|
8
7
|
createAuthorizationURL,
|
|
@@ -994,9 +994,17 @@ export type BetterAuthOptions = {
|
|
|
994
994
|
| undefined;
|
|
995
995
|
/**
|
|
996
996
|
* List of trusted origins.
|
|
997
|
+
*
|
|
998
|
+
* @param request - The request object.
|
|
999
|
+
* It'll be undefined if no request was
|
|
1000
|
+
* made. Like during a create context call
|
|
1001
|
+
* or `auth.api` call.
|
|
1002
|
+
*
|
|
1003
|
+
* Trusted origins will be dynamically
|
|
1004
|
+
* calculated based on the request.
|
|
997
1005
|
*/
|
|
998
1006
|
trustedOrigins?:
|
|
999
|
-
| (string[] | ((request
|
|
1007
|
+
| (string[] | ((request?: Request | undefined) => Awaitable<string[]>))
|
|
1000
1008
|
| undefined;
|
|
1001
1009
|
/**
|
|
1002
1010
|
* Rate limiting configuration
|
|
@@ -114,4 +114,14 @@ export interface BetterAuthClientPlugin {
|
|
|
114
114
|
* plugin or any plugin the user might have added.
|
|
115
115
|
*/
|
|
116
116
|
atomListeners?: ClientAtomListener[] | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* The error codes returned by the plugin
|
|
119
|
+
*/
|
|
120
|
+
$ERROR_CODES?: Record<
|
|
121
|
+
string,
|
|
122
|
+
{
|
|
123
|
+
code: string;
|
|
124
|
+
message: string;
|
|
125
|
+
}
|
|
126
|
+
>;
|
|
117
127
|
}
|
package/src/types/plugin.ts
CHANGED
|
@@ -145,7 +145,7 @@ export type BetterAuthPlugin = {
|
|
|
145
145
|
/**
|
|
146
146
|
* The error codes returned by the plugin
|
|
147
147
|
*/
|
|
148
|
-
$ERROR_CODES?: Record<string, string> | undefined;
|
|
148
|
+
$ERROR_CODES?: Record<string, { code: string; message: string }> | undefined;
|
|
149
149
|
/**
|
|
150
150
|
* All database operations that are performed by the plugin
|
|
151
151
|
*
|
package/src/utils/error-codes.ts
CHANGED
|
@@ -46,6 +46,20 @@ type ValidateErrorCodes<T> = {
|
|
|
46
46
|
|
|
47
47
|
export function defineErrorCodes<const T extends Record<string, string>>(
|
|
48
48
|
codes: ValidateErrorCodes<T>,
|
|
49
|
-
):
|
|
50
|
-
|
|
49
|
+
): {
|
|
50
|
+
[K in keyof T]: {
|
|
51
|
+
code: K;
|
|
52
|
+
message: T[K];
|
|
53
|
+
};
|
|
54
|
+
} {
|
|
55
|
+
return Object.fromEntries(
|
|
56
|
+
Object.entries(codes).map(([key, value]) => [
|
|
57
|
+
key,
|
|
58
|
+
{
|
|
59
|
+
code: key,
|
|
60
|
+
message: value,
|
|
61
|
+
toString: () => value,
|
|
62
|
+
},
|
|
63
|
+
]),
|
|
64
|
+
) as any;
|
|
51
65
|
}
|