@better-auth/core 1.4.12 → 1.4.14
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 +172 -35
- package/dist/api/index.d.mts +178 -1
- package/dist/api/index.mjs +2 -1
- package/dist/context/endpoint-context.d.mts +19 -0
- package/dist/context/endpoint-context.mjs +31 -0
- package/dist/context/global.d.mts +7 -0
- package/dist/context/global.mjs +37 -0
- package/dist/context/index.d.mts +5 -53
- package/dist/context/index.mjs +5 -2
- package/dist/context/request-state.d.mts +27 -0
- package/dist/context/request-state.mjs +49 -0
- package/dist/context/transaction.d.mts +16 -0
- package/dist/context/transaction.mjs +52 -0
- package/dist/db/adapter/factory.d.mts +27 -0
- package/dist/db/adapter/factory.mjs +738 -0
- package/dist/db/adapter/get-default-field-name.d.mts +18 -0
- package/dist/db/adapter/get-default-field-name.mjs +38 -0
- package/dist/db/adapter/get-default-model-name.d.mts +12 -0
- package/dist/db/adapter/get-default-model-name.mjs +32 -0
- package/dist/db/adapter/get-field-attributes.d.mts +29 -0
- package/dist/db/adapter/get-field-attributes.mjs +39 -0
- package/dist/db/adapter/get-field-name.d.mts +18 -0
- package/dist/db/adapter/get-field-name.mjs +33 -0
- package/dist/db/adapter/get-id-field.d.mts +39 -0
- package/dist/db/adapter/get-id-field.mjs +68 -0
- package/dist/db/adapter/get-model-name.d.mts +12 -0
- package/dist/db/adapter/get-model-name.mjs +23 -0
- package/dist/db/adapter/index.d.mts +513 -1
- package/dist/db/adapter/index.mjs +8 -970
- package/dist/db/adapter/types.d.mts +139 -0
- package/dist/db/adapter/utils.d.mts +7 -0
- package/dist/db/adapter/utils.mjs +38 -0
- package/dist/db/get-tables.d.mts +8 -0
- package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +7 -1
- package/dist/db/index.d.mts +10 -2
- package/dist/db/index.mjs +7 -60
- package/dist/db/plugin.d.mts +12 -0
- package/dist/db/schema/account.d.mts +26 -0
- package/dist/db/schema/account.mjs +19 -0
- package/dist/db/schema/rate-limit.d.mts +14 -0
- package/dist/db/schema/rate-limit.mjs +11 -0
- package/dist/db/schema/session.d.mts +21 -0
- package/dist/db/schema/session.mjs +14 -0
- package/dist/db/schema/shared.d.mts +10 -0
- package/dist/db/schema/shared.mjs +11 -0
- package/dist/db/schema/user.d.mts +20 -0
- package/dist/db/schema/user.mjs +13 -0
- package/dist/db/schema/verification.d.mts +19 -0
- package/dist/db/schema/verification.mjs +12 -0
- package/dist/db/type.d.mts +143 -0
- package/dist/env/color-depth.d.mts +4 -0
- package/dist/env/color-depth.mjs +88 -0
- package/dist/env/env-impl.d.mts +32 -0
- package/dist/env/env-impl.mjs +82 -0
- package/dist/env/index.d.mts +4 -2
- package/dist/env/index.mjs +3 -1
- package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
- package/dist/env/logger.mjs +81 -0
- package/dist/error/codes.d.mts +48 -0
- package/dist/{error-DP1xOn7P.mjs → error/codes.mjs} +3 -14
- package/dist/error/index.d.mts +5 -48
- package/dist/error/index.mjs +12 -3
- package/dist/index.d.mts +8 -2
- package/dist/oauth2/client-credentials-token.d.mts +36 -0
- package/dist/oauth2/client-credentials-token.mjs +54 -0
- package/dist/oauth2/create-authorization-url.d.mts +45 -0
- package/dist/oauth2/create-authorization-url.mjs +42 -0
- package/dist/oauth2/index.d.mts +8 -2
- package/dist/oauth2/index.mjs +6 -2
- package/dist/oauth2/oauth-provider.d.mts +194 -0
- package/dist/oauth2/refresh-access-token.d.mts +36 -0
- package/dist/oauth2/refresh-access-token.mjs +58 -0
- package/dist/oauth2/utils.d.mts +7 -0
- package/dist/oauth2/utils.mjs +27 -0
- package/dist/oauth2/validate-authorization-code.d.mts +55 -0
- package/dist/oauth2/validate-authorization-code.mjs +71 -0
- package/dist/oauth2/verify.d.mts +49 -0
- package/dist/oauth2/verify.mjs +95 -0
- package/dist/social-providers/apple.d.mts +119 -0
- package/dist/social-providers/apple.mjs +102 -0
- package/dist/social-providers/atlassian.d.mts +72 -0
- package/dist/social-providers/atlassian.mjs +83 -0
- package/dist/social-providers/cognito.d.mts +87 -0
- package/dist/social-providers/cognito.mjs +166 -0
- package/dist/social-providers/discord.d.mts +126 -0
- package/dist/social-providers/discord.mjs +64 -0
- package/dist/social-providers/dropbox.d.mts +71 -0
- package/dist/social-providers/dropbox.mjs +75 -0
- package/dist/social-providers/facebook.d.mts +81 -0
- package/dist/social-providers/facebook.mjs +120 -0
- package/dist/social-providers/figma.d.mts +63 -0
- package/dist/social-providers/figma.mjs +86 -0
- package/dist/social-providers/github.d.mts +104 -0
- package/dist/social-providers/github.mjs +80 -0
- package/dist/social-providers/gitlab.d.mts +125 -0
- package/dist/social-providers/gitlab.mjs +82 -0
- package/dist/social-providers/google.d.mts +99 -0
- package/dist/social-providers/google.mjs +109 -0
- package/dist/social-providers/huggingface.d.mts +85 -0
- package/dist/social-providers/huggingface.mjs +75 -0
- package/dist/social-providers/index.d.mts +1723 -1
- package/dist/social-providers/index.mjs +33 -2570
- package/dist/social-providers/kakao.d.mts +163 -0
- package/dist/social-providers/kakao.mjs +72 -0
- package/dist/social-providers/kick.d.mts +75 -0
- package/dist/social-providers/kick.mjs +71 -0
- package/dist/social-providers/line.d.mts +107 -0
- package/dist/social-providers/line.mjs +113 -0
- package/dist/social-providers/linear.d.mts +70 -0
- package/dist/social-providers/linear.mjs +88 -0
- package/dist/social-providers/linkedin.d.mts +69 -0
- package/dist/social-providers/linkedin.mjs +76 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
- package/dist/social-providers/microsoft-entra-id.mjs +106 -0
- package/dist/social-providers/naver.d.mts +104 -0
- package/dist/social-providers/naver.mjs +67 -0
- package/dist/social-providers/notion.d.mts +66 -0
- package/dist/social-providers/notion.mjs +75 -0
- package/dist/social-providers/paybin.d.mts +73 -0
- package/dist/social-providers/paybin.mjs +85 -0
- package/dist/social-providers/paypal.d.mts +131 -0
- package/dist/social-providers/paypal.mjs +144 -0
- package/dist/social-providers/polar.d.mts +76 -0
- package/dist/social-providers/polar.mjs +73 -0
- package/dist/social-providers/reddit.d.mts +64 -0
- package/dist/social-providers/reddit.mjs +83 -0
- package/dist/social-providers/roblox.d.mts +72 -0
- package/dist/social-providers/roblox.mjs +59 -0
- package/dist/social-providers/salesforce.d.mts +81 -0
- package/dist/social-providers/salesforce.mjs +91 -0
- package/dist/social-providers/slack.d.mts +85 -0
- package/dist/social-providers/slack.mjs +68 -0
- package/dist/social-providers/spotify.d.mts +65 -0
- package/dist/social-providers/spotify.mjs +71 -0
- package/dist/social-providers/tiktok.d.mts +171 -0
- package/dist/social-providers/tiktok.mjs +62 -0
- package/dist/social-providers/twitch.d.mts +81 -0
- package/dist/social-providers/twitch.mjs +78 -0
- package/dist/social-providers/twitter.d.mts +140 -0
- package/dist/social-providers/twitter.mjs +87 -0
- package/dist/social-providers/vercel.d.mts +64 -0
- package/dist/social-providers/vercel.mjs +61 -0
- package/dist/social-providers/vk.d.mts +72 -0
- package/dist/social-providers/vk.mjs +83 -0
- package/dist/social-providers/zoom.d.mts +173 -0
- package/dist/social-providers/zoom.mjs +72 -0
- package/dist/types/context.d.mts +215 -0
- package/dist/types/cookie.d.mts +15 -0
- package/dist/types/helper.d.mts +8 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1272 -0
- package/dist/types/plugin-client.d.mts +103 -0
- package/dist/types/plugin.d.mts +121 -0
- package/dist/utils/deprecate.d.mts +10 -0
- package/dist/utils/deprecate.mjs +17 -0
- package/dist/utils/error-codes.d.mts +9 -0
- package/dist/utils/error-codes.mjs +7 -0
- package/dist/utils/id.d.mts +4 -0
- package/dist/utils/id.mjs +9 -0
- package/dist/utils/index.d.mts +5 -26
- package/dist/utils/index.mjs +5 -2
- package/dist/utils/json.d.mts +4 -0
- package/dist/utils/json.mjs +25 -0
- package/dist/utils/string.d.mts +4 -0
- package/dist/utils/string.mjs +7 -0
- package/package.json +3 -3
- package/src/context/endpoint-context.ts +7 -15
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +1 -0
- package/src/context/request-state.ts +7 -12
- package/src/context/transaction.ts +7 -16
- package/src/db/adapter/factory.ts +13 -13
- package/src/db/adapter/get-default-model-name.ts +1 -1
- package/src/db/adapter/get-id-field.ts +2 -2
- package/src/db/get-tables.ts +6 -0
- package/src/error/index.ts +2 -3
- package/src/social-providers/figma.ts +5 -3
- package/src/social-providers/gitlab.ts +1 -1
- package/src/types/context.ts +137 -131
- package/src/types/cookie.ts +6 -4
- package/src/types/index.ts +2 -1
- package/src/types/init-options.ts +6 -0
- package/tsdown.config.ts +9 -0
- package/dist/context-BGZ8V6DD.mjs +0 -126
- package/dist/env-DbssmzoK.mjs +0 -245
- package/dist/index-zgYuzZ7O.d.mts +0 -8020
- package/dist/oauth2-COJkghlT.mjs +0 -326
- package/dist/utils-U2L7n92V.mjs +0 -59
|
@@ -200,7 +200,7 @@ export const createAdapterFactory =
|
|
|
200
200
|
let value = data[field];
|
|
201
201
|
const fieldAttributes = fields[field];
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
const newFieldName: string =
|
|
204
204
|
newMappedKeys[field] || fields[field]!.fieldName || field;
|
|
205
205
|
if (
|
|
206
206
|
value === undefined &&
|
|
@@ -335,7 +335,7 @@ export const createAdapterFactory =
|
|
|
335
335
|
newValue = await field.transform.output(newValue);
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
|
|
338
|
+
const newFieldName: string = newMappedKeys[key] || key;
|
|
339
339
|
|
|
340
340
|
if (originalKey === "id" || field.references?.field === "id") {
|
|
341
341
|
// Even if `useNumberId` is true, we must always return a string `id` output.
|
|
@@ -392,7 +392,7 @@ export const createAdapterFactory =
|
|
|
392
392
|
unsafe_model = getDefaultModelName(unsafe_model);
|
|
393
393
|
// for now we just transform the base model
|
|
394
394
|
// later we append the joined models to this object.
|
|
395
|
-
|
|
395
|
+
const transformedData: Record<string, any> = await transformSingleOutput(
|
|
396
396
|
data,
|
|
397
397
|
unsafe_model,
|
|
398
398
|
select,
|
|
@@ -443,7 +443,7 @@ export const createAdapterFactory =
|
|
|
443
443
|
joinedData = [joinedData];
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
-
|
|
446
|
+
const transformed = [];
|
|
447
447
|
|
|
448
448
|
if (Array.isArray(joinedData)) {
|
|
449
449
|
for (const item of joinedData) {
|
|
@@ -822,7 +822,7 @@ export const createAdapterFactory =
|
|
|
822
822
|
forceAllowId?: boolean;
|
|
823
823
|
}): Promise<R> => {
|
|
824
824
|
transactionId++;
|
|
825
|
-
|
|
825
|
+
const thisTransactionId = transactionId;
|
|
826
826
|
const model = getModelName(unsafeModel);
|
|
827
827
|
unsafeModel = getDefaultModelName(unsafeModel);
|
|
828
828
|
if (
|
|
@@ -903,7 +903,7 @@ export const createAdapterFactory =
|
|
|
903
903
|
update: Record<string, any>;
|
|
904
904
|
}): Promise<T | null> => {
|
|
905
905
|
transactionId++;
|
|
906
|
-
|
|
906
|
+
const thisTransactionId = transactionId;
|
|
907
907
|
unsafeModel = getDefaultModelName(unsafeModel);
|
|
908
908
|
const model = getModelName(unsafeModel);
|
|
909
909
|
const where = transformWhereClause({
|
|
@@ -965,7 +965,7 @@ export const createAdapterFactory =
|
|
|
965
965
|
update: Record<string, any>;
|
|
966
966
|
}) => {
|
|
967
967
|
transactionId++;
|
|
968
|
-
|
|
968
|
+
const thisTransactionId = transactionId;
|
|
969
969
|
const model = getModelName(unsafeModel);
|
|
970
970
|
const where = transformWhereClause({
|
|
971
971
|
model: unsafeModel,
|
|
@@ -1021,7 +1021,7 @@ export const createAdapterFactory =
|
|
|
1021
1021
|
join?: JoinOption;
|
|
1022
1022
|
}) => {
|
|
1023
1023
|
transactionId++;
|
|
1024
|
-
|
|
1024
|
+
const thisTransactionId = transactionId;
|
|
1025
1025
|
const model = getModelName(unsafeModel);
|
|
1026
1026
|
const where = transformWhereClause({
|
|
1027
1027
|
model: unsafeModel,
|
|
@@ -1095,7 +1095,7 @@ export const createAdapterFactory =
|
|
|
1095
1095
|
join?: JoinOption;
|
|
1096
1096
|
}) => {
|
|
1097
1097
|
transactionId++;
|
|
1098
|
-
|
|
1098
|
+
const thisTransactionId = transactionId;
|
|
1099
1099
|
const limit =
|
|
1100
1100
|
unsafeLimit ??
|
|
1101
1101
|
options.advanced?.database?.defaultFindManyLimit ??
|
|
@@ -1173,7 +1173,7 @@ export const createAdapterFactory =
|
|
|
1173
1173
|
where: Where[];
|
|
1174
1174
|
}) => {
|
|
1175
1175
|
transactionId++;
|
|
1176
|
-
|
|
1176
|
+
const thisTransactionId = transactionId;
|
|
1177
1177
|
const model = getModelName(unsafeModel);
|
|
1178
1178
|
const where = transformWhereClause({
|
|
1179
1179
|
model: unsafeModel,
|
|
@@ -1206,7 +1206,7 @@ export const createAdapterFactory =
|
|
|
1206
1206
|
where: Where[];
|
|
1207
1207
|
}) => {
|
|
1208
1208
|
transactionId++;
|
|
1209
|
-
|
|
1209
|
+
const thisTransactionId = transactionId;
|
|
1210
1210
|
const model = getModelName(unsafeModel);
|
|
1211
1211
|
const where = transformWhereClause({
|
|
1212
1212
|
model: unsafeModel,
|
|
@@ -1240,7 +1240,7 @@ export const createAdapterFactory =
|
|
|
1240
1240
|
where?: Where[];
|
|
1241
1241
|
}) => {
|
|
1242
1242
|
transactionId++;
|
|
1243
|
-
|
|
1243
|
+
const thisTransactionId = transactionId;
|
|
1244
1244
|
const model = getModelName(unsafeModel);
|
|
1245
1245
|
const where = transformWhereClause({
|
|
1246
1246
|
model: unsafeModel,
|
|
@@ -1350,7 +1350,7 @@ export const createAdapterFactory =
|
|
|
1350
1350
|
}
|
|
1351
1351
|
|
|
1352
1352
|
//`${colors.fg.blue}|${colors.reset} `,
|
|
1353
|
-
|
|
1353
|
+
const log: any[] = logs
|
|
1354
1354
|
.reverse()
|
|
1355
1355
|
.map((log) => {
|
|
1356
1356
|
log.args[0] = `\n${log.args[0]}`;
|
|
@@ -23,7 +23,7 @@ export const initGetDefaultModelName = ({
|
|
|
23
23
|
// It's possible this `model` could had applied `usePlural`.
|
|
24
24
|
// Thus we'll try the search but without the trailing `s`.
|
|
25
25
|
if (usePlural && model.charAt(model.length - 1) === "s") {
|
|
26
|
-
|
|
26
|
+
const pluralessModel = model.slice(0, -1);
|
|
27
27
|
let m = schema[pluralessModel] ? pluralessModel : undefined;
|
|
28
28
|
if (!m) {
|
|
29
29
|
m = Object.entries(schema).find(
|
|
@@ -36,7 +36,7 @@ export const initGetIdField = ({
|
|
|
36
36
|
options.advanced?.database?.generateId === "serial";
|
|
37
37
|
const useUUIDs = options.advanced?.database?.generateId === "uuid";
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const shouldGenerateId: boolean = (() => {
|
|
40
40
|
if (disableIdGeneration) {
|
|
41
41
|
return false;
|
|
42
42
|
} else if (useNumberId && !forceAllowId) {
|
|
@@ -58,7 +58,7 @@ export const initGetIdField = ({
|
|
|
58
58
|
? {
|
|
59
59
|
defaultValue() {
|
|
60
60
|
if (disableIdGeneration) return undefined;
|
|
61
|
-
|
|
61
|
+
const generateId = options.advanced?.database?.generateId;
|
|
62
62
|
if (generateId === false || useNumberId) return undefined;
|
|
63
63
|
if (typeof generateId === "function") {
|
|
64
64
|
return generateId({
|
package/src/db/get-tables.ts
CHANGED
|
@@ -183,21 +183,25 @@ export const getAuthTables = (
|
|
|
183
183
|
accessToken: {
|
|
184
184
|
type: "string",
|
|
185
185
|
required: false,
|
|
186
|
+
returned: false,
|
|
186
187
|
fieldName: options.account?.fields?.accessToken || "accessToken",
|
|
187
188
|
},
|
|
188
189
|
refreshToken: {
|
|
189
190
|
type: "string",
|
|
190
191
|
required: false,
|
|
192
|
+
returned: false,
|
|
191
193
|
fieldName: options.account?.fields?.refreshToken || "refreshToken",
|
|
192
194
|
},
|
|
193
195
|
idToken: {
|
|
194
196
|
type: "string",
|
|
195
197
|
required: false,
|
|
198
|
+
returned: false,
|
|
196
199
|
fieldName: options.account?.fields?.idToken || "idToken",
|
|
197
200
|
},
|
|
198
201
|
accessTokenExpiresAt: {
|
|
199
202
|
type: "date",
|
|
200
203
|
required: false,
|
|
204
|
+
returned: false,
|
|
201
205
|
fieldName:
|
|
202
206
|
options.account?.fields?.accessTokenExpiresAt ||
|
|
203
207
|
"accessTokenExpiresAt",
|
|
@@ -205,6 +209,7 @@ export const getAuthTables = (
|
|
|
205
209
|
refreshTokenExpiresAt: {
|
|
206
210
|
type: "date",
|
|
207
211
|
required: false,
|
|
212
|
+
returned: false,
|
|
208
213
|
fieldName:
|
|
209
214
|
options.account?.fields?.refreshTokenExpiresAt ||
|
|
210
215
|
"refreshTokenExpiresAt",
|
|
@@ -217,6 +222,7 @@ export const getAuthTables = (
|
|
|
217
222
|
password: {
|
|
218
223
|
type: "string",
|
|
219
224
|
required: false,
|
|
225
|
+
returned: false,
|
|
220
226
|
fieldName: options.account?.fields?.password || "password",
|
|
221
227
|
},
|
|
222
228
|
createdAt: {
|
package/src/error/index.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export class BetterAuthError extends Error {
|
|
2
|
-
constructor(message: string, cause?:
|
|
3
|
-
super(message);
|
|
2
|
+
constructor(message: string, options?: { cause?: unknown | undefined }) {
|
|
3
|
+
super(message, options);
|
|
4
4
|
this.name = "BetterAuthError";
|
|
5
5
|
this.message = message;
|
|
6
|
-
this.cause = cause;
|
|
7
6
|
this.stack = "";
|
|
8
7
|
}
|
|
9
8
|
}
|
|
@@ -34,7 +34,7 @@ export const figma = (options: FigmaOptions) => {
|
|
|
34
34
|
throw new BetterAuthError("codeVerifier is required for Figma");
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
const _scopes = options.disableDefaultScope ? [] : ["
|
|
37
|
+
const _scopes = options.disableDefaultScope ? [] : ["current_user:read"];
|
|
38
38
|
if (options.scope) _scopes.push(...options.scope);
|
|
39
39
|
if (scopes) _scopes.push(...scopes);
|
|
40
40
|
|
|
@@ -56,7 +56,8 @@ export const figma = (options: FigmaOptions) => {
|
|
|
56
56
|
codeVerifier,
|
|
57
57
|
redirectURI,
|
|
58
58
|
options,
|
|
59
|
-
tokenEndpoint: "https://
|
|
59
|
+
tokenEndpoint: "https://api.figma.com/v1/oauth/token",
|
|
60
|
+
authentication: "basic",
|
|
60
61
|
});
|
|
61
62
|
},
|
|
62
63
|
refreshAccessToken: options.refreshAccessToken
|
|
@@ -69,7 +70,8 @@ export const figma = (options: FigmaOptions) => {
|
|
|
69
70
|
clientKey: options.clientKey,
|
|
70
71
|
clientSecret: options.clientSecret,
|
|
71
72
|
},
|
|
72
|
-
tokenEndpoint: "https://
|
|
73
|
+
tokenEndpoint: "https://api.figma.com/v1/oauth/token",
|
|
74
|
+
authentication: "basic",
|
|
73
75
|
});
|
|
74
76
|
},
|
|
75
77
|
async getUserInfo(token) {
|
|
@@ -65,7 +65,7 @@ const cleanDoubleSlashes = (input: string = "") => {
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
const issuerToEndpoints = (issuer?: string | undefined) => {
|
|
68
|
-
|
|
68
|
+
const baseUrl = issuer || "https://gitlab.com";
|
|
69
69
|
return {
|
|
70
70
|
authorizationEndpoint: cleanDoubleSlashes(`${baseUrl}/oauth/authorize`),
|
|
71
71
|
tokenEndpoint: cleanDoubleSlashes(`${baseUrl}/oauth/token`),
|
package/src/types/context.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
import type { DBAdapter, Where } from "../db/adapter";
|
|
12
12
|
import type { createLogger } from "../env";
|
|
13
13
|
import type { OAuthProvider } from "../oauth2";
|
|
14
|
-
import type { BetterAuthCookies } from "./cookie";
|
|
14
|
+
import type { BetterAuthCookie, BetterAuthCookies } from "./cookie";
|
|
15
15
|
import type {
|
|
16
16
|
BetterAuthOptions,
|
|
17
17
|
BetterAuthRateLimitOptions,
|
|
@@ -150,10 +150,7 @@ export interface InternalAdapter<
|
|
|
150
150
|
type CreateCookieGetterFn = (
|
|
151
151
|
cookieName: string,
|
|
152
152
|
overrideAttributes?: Partial<CookieOptions> | undefined,
|
|
153
|
-
) =>
|
|
154
|
-
name: string;
|
|
155
|
-
attributes: CookieOptions;
|
|
156
|
-
};
|
|
153
|
+
) => BetterAuthCookie;
|
|
157
154
|
|
|
158
155
|
type CheckPasswordFn<Options extends BetterAuthOptions = BetterAuthOptions> = (
|
|
159
156
|
userId: string,
|
|
@@ -166,139 +163,148 @@ export type PluginContext = {
|
|
|
166
163
|
) => Plugin | null;
|
|
167
164
|
};
|
|
168
165
|
|
|
166
|
+
export type InfoContext = {
|
|
167
|
+
appName: string;
|
|
168
|
+
baseURL: string;
|
|
169
|
+
version: string;
|
|
170
|
+
};
|
|
171
|
+
|
|
169
172
|
export type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> =
|
|
170
|
-
PluginContext &
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
trustedOrigins: string[];
|
|
175
|
-
/**
|
|
176
|
-
* Verifies whether url is a trusted origin according to the "trustedOrigins" configuration
|
|
177
|
-
* @param url The url to verify against the "trustedOrigins" configuration
|
|
178
|
-
* @param settings Specify supported pattern matching settings
|
|
179
|
-
* @returns {boolean} true if the URL matches the origin pattern, false otherwise.
|
|
180
|
-
*/
|
|
181
|
-
isTrustedOrigin: (
|
|
182
|
-
url: string,
|
|
183
|
-
settings?: { allowRelativePaths: boolean },
|
|
184
|
-
) => boolean;
|
|
185
|
-
oauthConfig: {
|
|
173
|
+
PluginContext &
|
|
174
|
+
InfoContext & {
|
|
175
|
+
options: Options;
|
|
176
|
+
trustedOrigins: string[];
|
|
186
177
|
/**
|
|
187
|
-
*
|
|
178
|
+
* Verifies whether url is a trusted origin according to the "trustedOrigins" configuration
|
|
179
|
+
* @param url The url to verify against the "trustedOrigins" configuration
|
|
180
|
+
* @param settings Specify supported pattern matching settings
|
|
181
|
+
* @returns {boolean} true if the URL matches the origin pattern, false otherwise.
|
|
188
182
|
*/
|
|
189
|
-
|
|
183
|
+
isTrustedOrigin: (
|
|
184
|
+
url: string,
|
|
185
|
+
settings?: { allowRelativePaths: boolean },
|
|
186
|
+
) => boolean;
|
|
187
|
+
oauthConfig: {
|
|
188
|
+
/**
|
|
189
|
+
* This is dangerous and should only be used in dev or staging environments.
|
|
190
|
+
*/
|
|
191
|
+
skipStateCookieCheck?: boolean | undefined;
|
|
192
|
+
/**
|
|
193
|
+
* Strategy for storing OAuth state
|
|
194
|
+
*
|
|
195
|
+
* - "cookie": Store state in an encrypted cookie (stateless)
|
|
196
|
+
* - "database": Store state in the database
|
|
197
|
+
*
|
|
198
|
+
* @default "cookie"
|
|
199
|
+
*/
|
|
200
|
+
storeStateStrategy: "database" | "cookie";
|
|
201
|
+
};
|
|
190
202
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @default "cookie"
|
|
203
|
+
* New session that will be set after the request
|
|
204
|
+
* meaning: there is a `set-cookie` header that will set
|
|
205
|
+
* the session cookie. This is the fetched session. And it's set
|
|
206
|
+
* by `setNewSession` method.
|
|
197
207
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
* meaning: there is a `set-cookie` header that will set
|
|
203
|
-
* the session cookie. This is the fetched session. And it's set
|
|
204
|
-
* by `setNewSession` method.
|
|
205
|
-
*/
|
|
206
|
-
newSession: {
|
|
207
|
-
session: Session & Record<string, any>;
|
|
208
|
-
user: User & Record<string, any>;
|
|
209
|
-
} | null;
|
|
210
|
-
session: {
|
|
211
|
-
session: Session & Record<string, any>;
|
|
212
|
-
user: User & Record<string, any>;
|
|
213
|
-
} | null;
|
|
214
|
-
setNewSession: (
|
|
208
|
+
newSession: {
|
|
209
|
+
session: Session & Record<string, any>;
|
|
210
|
+
user: User & Record<string, any>;
|
|
211
|
+
} | null;
|
|
215
212
|
session: {
|
|
216
213
|
session: Session & Record<string, any>;
|
|
217
214
|
user: User & Record<string, any>;
|
|
218
|
-
} | null
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
verify: (data: { password: string; hash: string }) => Promise<boolean>;
|
|
252
|
-
config: {
|
|
253
|
-
minPasswordLength: number;
|
|
254
|
-
maxPasswordLength: number;
|
|
215
|
+
} | null;
|
|
216
|
+
setNewSession: (
|
|
217
|
+
session: {
|
|
218
|
+
session: Session & Record<string, any>;
|
|
219
|
+
user: User & Record<string, any>;
|
|
220
|
+
} | null,
|
|
221
|
+
) => void;
|
|
222
|
+
socialProviders: OAuthProvider[];
|
|
223
|
+
authCookies: BetterAuthCookies;
|
|
224
|
+
logger: ReturnType<typeof createLogger>;
|
|
225
|
+
rateLimit: {
|
|
226
|
+
enabled: boolean;
|
|
227
|
+
window: number;
|
|
228
|
+
max: number;
|
|
229
|
+
storage: "memory" | "database" | "secondary-storage";
|
|
230
|
+
} & Omit<
|
|
231
|
+
BetterAuthRateLimitOptions,
|
|
232
|
+
"enabled" | "window" | "max" | "storage"
|
|
233
|
+
>;
|
|
234
|
+
adapter: DBAdapter<Options>;
|
|
235
|
+
internalAdapter: InternalAdapter<Options>;
|
|
236
|
+
createAuthCookie: CreateCookieGetterFn;
|
|
237
|
+
secret: string;
|
|
238
|
+
sessionConfig: {
|
|
239
|
+
updateAge: number;
|
|
240
|
+
expiresIn: number;
|
|
241
|
+
freshAge: number;
|
|
242
|
+
cookieRefreshCache:
|
|
243
|
+
| false
|
|
244
|
+
| {
|
|
245
|
+
enabled: true;
|
|
246
|
+
updateAge: number;
|
|
247
|
+
};
|
|
255
248
|
};
|
|
256
|
-
|
|
249
|
+
generateId: (options: {
|
|
250
|
+
model: ModelNames;
|
|
251
|
+
size?: number | undefined;
|
|
252
|
+
}) => string | false;
|
|
253
|
+
secondaryStorage: SecondaryStorage | undefined;
|
|
254
|
+
password: {
|
|
255
|
+
hash: (password: string) => Promise<string>;
|
|
256
|
+
verify: (data: { password: string; hash: string }) => Promise<boolean>;
|
|
257
|
+
config: {
|
|
258
|
+
minPasswordLength: number;
|
|
259
|
+
maxPasswordLength: number;
|
|
260
|
+
};
|
|
261
|
+
checkPassword: CheckPasswordFn<Options>;
|
|
262
|
+
};
|
|
263
|
+
tables: BetterAuthDBSchema;
|
|
264
|
+
runMigrations: () => Promise<void>;
|
|
265
|
+
publishTelemetry: (event: {
|
|
266
|
+
type: string;
|
|
267
|
+
anonymousId?: string | undefined;
|
|
268
|
+
payload: Record<string, any>;
|
|
269
|
+
}) => Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* Skip origin check for requests.
|
|
272
|
+
*
|
|
273
|
+
* - `true`: Skip for ALL requests (DANGEROUS - disables CSRF protection)
|
|
274
|
+
* - `string[]`: Skip only for specific paths (e.g., SAML callbacks)
|
|
275
|
+
* - `false`: Enable origin check (default)
|
|
276
|
+
*
|
|
277
|
+
* Paths support prefix matching (e.g., "/sso/saml2/callback" matches
|
|
278
|
+
* "/sso/saml2/callback/provider-name").
|
|
279
|
+
*
|
|
280
|
+
* @default false (true in test environments)
|
|
281
|
+
*/
|
|
282
|
+
skipOriginCheck: boolean | string[];
|
|
283
|
+
/**
|
|
284
|
+
* This skips the CSRF check for all requests.
|
|
285
|
+
*
|
|
286
|
+
* This is inferred from the `options.advanced?.
|
|
287
|
+
* disableCSRFCheck` option.
|
|
288
|
+
*
|
|
289
|
+
* @default false
|
|
290
|
+
*/
|
|
291
|
+
skipCSRFCheck: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* Background task handler for deferred operations.
|
|
294
|
+
*
|
|
295
|
+
* This is inferred from the `options.advanced?.backgroundTasks?.handler` option.
|
|
296
|
+
* Defaults to a no-op that just runs the promise.
|
|
297
|
+
*/
|
|
298
|
+
runInBackground: (promise: Promise<void>) => void;
|
|
299
|
+
/**
|
|
300
|
+
* Runs a task in the background if `runInBackground` is configured,
|
|
301
|
+
* otherwise awaits the task directly.
|
|
302
|
+
*
|
|
303
|
+
* This is useful for operations like sending emails where we want
|
|
304
|
+
* to avoid blocking the response when possible (for timing attack
|
|
305
|
+
* mitigation), but still ensure the operation completes.
|
|
306
|
+
*/
|
|
307
|
+
runInBackgroundOrAwait: (
|
|
308
|
+
promise: Promise<unknown> | Promise<void> | void | unknown,
|
|
309
|
+
) => Promise<unknown>;
|
|
257
310
|
};
|
|
258
|
-
tables: BetterAuthDBSchema;
|
|
259
|
-
runMigrations: () => Promise<void>;
|
|
260
|
-
publishTelemetry: (event: {
|
|
261
|
-
type: string;
|
|
262
|
-
anonymousId?: string | undefined;
|
|
263
|
-
payload: Record<string, any>;
|
|
264
|
-
}) => Promise<void>;
|
|
265
|
-
/**
|
|
266
|
-
* This skips the origin check for all requests.
|
|
267
|
-
*
|
|
268
|
-
* set to true by default for `test` environments and `false`
|
|
269
|
-
* for other environments.
|
|
270
|
-
*
|
|
271
|
-
* It's inferred from the `options.advanced?.disableCSRFCheck`
|
|
272
|
-
* option or `options.advanced?.disableOriginCheck` option.
|
|
273
|
-
*
|
|
274
|
-
* @default false
|
|
275
|
-
*/
|
|
276
|
-
skipOriginCheck: boolean;
|
|
277
|
-
/**
|
|
278
|
-
* This skips the CSRF check for all requests.
|
|
279
|
-
*
|
|
280
|
-
* This is inferred from the `options.advanced?.
|
|
281
|
-
* disableCSRFCheck` option.
|
|
282
|
-
*
|
|
283
|
-
* @default false
|
|
284
|
-
*/
|
|
285
|
-
skipCSRFCheck: boolean;
|
|
286
|
-
/**
|
|
287
|
-
* Background task handler for deferred operations.
|
|
288
|
-
*
|
|
289
|
-
* This is inferred from the `options.advanced?.backgroundTasks?.handler` option.
|
|
290
|
-
* Defaults to a no-op that just runs the promise.
|
|
291
|
-
*/
|
|
292
|
-
runInBackground: (promise: Promise<void>) => void;
|
|
293
|
-
/**
|
|
294
|
-
* Runs a task in the background if `runInBackground` is configured,
|
|
295
|
-
* otherwise awaits the task directly.
|
|
296
|
-
*
|
|
297
|
-
* This is useful for operations like sending emails where we want
|
|
298
|
-
* to avoid blocking the response when possible (for timing attack
|
|
299
|
-
* mitigation), but still ensure the operation completes.
|
|
300
|
-
*/
|
|
301
|
-
runInBackgroundOrAwait: (
|
|
302
|
-
promise: Promise<unknown> | Promise<void> | void | unknown,
|
|
303
|
-
) => Promise<unknown>;
|
|
304
|
-
};
|
package/src/types/cookie.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { CookieOptions } from "better-call";
|
|
2
2
|
|
|
3
|
+
export type BetterAuthCookie = { name: string; attributes: CookieOptions };
|
|
4
|
+
|
|
3
5
|
export type BetterAuthCookies = {
|
|
4
|
-
sessionToken:
|
|
5
|
-
sessionData:
|
|
6
|
-
accountData:
|
|
7
|
-
dontRememberToken:
|
|
6
|
+
sessionToken: BetterAuthCookie;
|
|
7
|
+
sessionData: BetterAuthCookie;
|
|
8
|
+
accountData: BetterAuthCookie;
|
|
9
|
+
dontRememberToken: BetterAuthCookie;
|
|
8
10
|
};
|
package/src/types/index.ts
CHANGED
|
@@ -2,10 +2,11 @@ export type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
2
2
|
export type {
|
|
3
3
|
AuthContext,
|
|
4
4
|
GenericEndpointContext,
|
|
5
|
+
InfoContext,
|
|
5
6
|
InternalAdapter,
|
|
6
7
|
PluginContext,
|
|
7
8
|
} from "./context";
|
|
8
|
-
export type { BetterAuthCookies } from "./cookie";
|
|
9
|
+
export type { BetterAuthCookie, BetterAuthCookies } from "./cookie";
|
|
9
10
|
export type * from "./helper";
|
|
10
11
|
export type {
|
|
11
12
|
BetterAuthAdvancedOptions,
|
|
@@ -311,6 +311,12 @@ export type BetterAuthAdvancedOptions = {
|
|
|
311
311
|
backgroundTasks?: {
|
|
312
312
|
handler: (promise: Promise<void>) => void;
|
|
313
313
|
};
|
|
314
|
+
/**
|
|
315
|
+
* Skip trailing slash validation in route matching
|
|
316
|
+
*
|
|
317
|
+
* @default false
|
|
318
|
+
*/
|
|
319
|
+
skipTrailingSlashes?: boolean | undefined;
|
|
314
320
|
};
|
|
315
321
|
|
|
316
322
|
export type BetterAuthOptions = {
|
package/tsdown.config.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
1
2
|
import { defineConfig } from "tsdown";
|
|
2
3
|
|
|
4
|
+
const packageJson = JSON.parse(
|
|
5
|
+
await readFile(new URL("./package.json", import.meta.url), "utf-8"),
|
|
6
|
+
);
|
|
7
|
+
|
|
3
8
|
export default defineConfig({
|
|
4
9
|
dts: { build: true, incremental: true },
|
|
5
10
|
format: ["esm"],
|
|
@@ -18,5 +23,9 @@ export default defineConfig({
|
|
|
18
23
|
"./src/error/index.ts",
|
|
19
24
|
],
|
|
20
25
|
external: ["@better-auth/core/async_hooks"],
|
|
26
|
+
env: {
|
|
27
|
+
BETTER_AUTH_VERSION: packageJson.version,
|
|
28
|
+
},
|
|
29
|
+
unbundle: true,
|
|
21
30
|
clean: true,
|
|
22
31
|
});
|