better-auth 1.6.25 → 1.6.27
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/dist/api/index.d.mts +74 -73
- package/dist/api/middlewares/authorization.d.mts +4 -4
- package/dist/api/middlewares/origin-check.d.mts +3 -3
- package/dist/api/rate-limiter/index.mjs +3 -3
- package/dist/api/routes/account.d.mts +6 -6
- package/dist/api/routes/email-verification.d.mts +1 -1
- package/dist/api/routes/password.d.mts +4 -4
- package/dist/api/routes/session.d.mts +16 -16
- package/dist/api/routes/session.mjs +2 -3
- package/dist/api/routes/sign-in.d.mts +1 -1
- package/dist/api/routes/sign-up.d.mts +1 -1
- package/dist/api/routes/update-session.d.mts +2 -2
- package/dist/api/routes/update-user.d.mts +11 -11
- package/dist/client/session-atom.mjs +33 -44
- package/dist/db/internal-adapter.mjs +23 -21
- package/dist/integrations/next-js.d.mts +2 -2
- package/dist/integrations/next-js.mjs +16 -2
- package/dist/integrations/svelte-kit.d.mts +1 -1
- package/dist/integrations/tanstack-start-solid.d.mts +1 -1
- package/dist/integrations/tanstack-start.d.mts +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/admin/admin.d.mts +25 -25
- package/dist/plugins/anonymous/index.d.mts +3 -3
- package/dist/plugins/anonymous/index.mjs +0 -1
- package/dist/plugins/bearer/index.d.mts +3 -3
- package/dist/plugins/custom-session/index.d.mts +1 -1
- package/dist/plugins/email-otp/index.d.mts +6 -6
- package/dist/plugins/email-otp/index.mjs +1 -1
- package/dist/plugins/email-otp/routes.mjs +9 -4
- package/dist/plugins/generic-oauth/index.d.mts +2 -2
- package/dist/plugins/jwt/adapter.mjs +5 -4
- package/dist/plugins/jwt/client.d.mts +4 -2
- package/dist/plugins/jwt/client.mjs +1 -1
- package/dist/plugins/jwt/index.d.mts +3 -3
- package/dist/plugins/last-login-method/index.d.mts +2 -2
- package/dist/plugins/magic-link/index.d.mts +2 -2
- package/dist/plugins/mcp/index.d.mts +3 -3
- package/dist/plugins/multi-session/index.d.mts +3 -3
- package/dist/plugins/oauth-popup/index.d.mts +1 -1
- package/dist/plugins/oauth-proxy/index.d.mts +3 -3
- package/dist/plugins/oauth-proxy/index.mjs +13 -3
- package/dist/plugins/oidc-provider/index.d.mts +6 -6
- package/dist/plugins/one-tap/client.d.mts +4 -3
- package/dist/plugins/one-tap/client.mjs +1 -1
- package/dist/plugins/one-time-token/index.d.mts +3 -3
- package/dist/plugins/organization/organization.d.mts +28 -4
- package/dist/plugins/organization/routes/crud-access-control.d.mts +140 -20
- package/dist/plugins/organization/routes/crud-invites.d.mts +149 -29
- package/dist/plugins/organization/routes/crud-members.d.mts +150 -30
- package/dist/plugins/organization/routes/crud-org.d.mts +96 -24
- package/dist/plugins/organization/routes/crud-team.d.mts +207 -39
- package/dist/plugins/phone-number/index.d.mts +1 -1
- package/dist/plugins/two-factor/backup-codes/index.d.mts +2 -2
- package/dist/plugins/two-factor/index.d.mts +10 -10
- package/dist/plugins/two-factor/totp/index.d.mts +2 -2
- package/dist/plugins/username/index.d.mts +1 -1
- package/package.json +15 -14
|
@@ -17,6 +17,8 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
17
17
|
const logger = ctx.logger;
|
|
18
18
|
const options = ctx.options;
|
|
19
19
|
const secondaryStorage = options.secondaryStorage;
|
|
20
|
+
const databaseStoresSessions = !secondaryStorage || options.session?.storeSessionInDatabase === true;
|
|
21
|
+
const preservesDatabaseSessions = secondaryStorage !== void 0 && options.session?.preserveSessionInDatabase === true;
|
|
20
22
|
const verificationConsumeLocks = /* @__PURE__ */ new Map();
|
|
21
23
|
let warnedNonAtomicConsume = false;
|
|
22
24
|
const sessionExpiration = options.session?.expiresIn || 3600 * 24 * 7;
|
|
@@ -55,6 +57,20 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
55
57
|
if (verificationConsumeLocks.get(key) === next) verificationConsumeLocks.delete(key);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
60
|
+
const deleteSecondaryStorageSessions = async (userId) => {
|
|
61
|
+
if (!secondaryStorage) return;
|
|
62
|
+
const activeSession = await secondaryStorage.get(`active-sessions-${userId}`);
|
|
63
|
+
const sessions = activeSession ? safeJSONParse(activeSession) : [];
|
|
64
|
+
if (!sessions) return;
|
|
65
|
+
for (const session of sessions) await secondaryStorage.delete(session.token);
|
|
66
|
+
await secondaryStorage.delete(`active-sessions-${userId}`);
|
|
67
|
+
};
|
|
68
|
+
const deleteDatabaseSessions = async (userId) => {
|
|
69
|
+
await deleteManyWithHooks([{
|
|
70
|
+
field: "userId",
|
|
71
|
+
value: userId
|
|
72
|
+
}], "session", void 0);
|
|
73
|
+
};
|
|
58
74
|
return {
|
|
59
75
|
createOAuthUser: async (user, account) => {
|
|
60
76
|
return runWithTransaction(adapter, async () => {
|
|
@@ -146,10 +162,8 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
146
162
|
return total;
|
|
147
163
|
},
|
|
148
164
|
deleteUser: async (userId) => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
value: userId
|
|
152
|
-
}], "session", void 0);
|
|
165
|
+
await deleteSecondaryStorageSessions(userId);
|
|
166
|
+
if (databaseStoresSessions) await deleteDatabaseSessions(userId);
|
|
153
167
|
await deleteManyWithHooks([{
|
|
154
168
|
field: "userId",
|
|
155
169
|
value: userId
|
|
@@ -271,7 +285,7 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
271
285
|
const sessionStringified = await secondaryStorage.get(sessionToken);
|
|
272
286
|
if (sessionStringified) try {
|
|
273
287
|
const s = typeof sessionStringified === "string" ? JSON.parse(sessionStringified) : sessionStringified;
|
|
274
|
-
if (!s)
|
|
288
|
+
if (!s) continue;
|
|
275
289
|
const expiresAt = new Date(s.session.expiresAt);
|
|
276
290
|
if (options?.onlyActiveSessions && expiresAt <= /* @__PURE__ */ new Date()) continue;
|
|
277
291
|
const session = {
|
|
@@ -377,9 +391,8 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
377
391
|
} else logger.error("Active sessions list not found in secondary storage");
|
|
378
392
|
}
|
|
379
393
|
await secondaryStorage.delete(token);
|
|
380
|
-
if (!options.session?.storeSessionInDatabase || ctx.options.session?.preserveSessionInDatabase) return;
|
|
381
394
|
}
|
|
382
|
-
await deleteWithHooks([{
|
|
395
|
+
if (databaseStoresSessions && !preservesDatabaseSessions) await deleteWithHooks([{
|
|
383
396
|
field: "token",
|
|
384
397
|
value: token
|
|
385
398
|
}], "session", void 0);
|
|
@@ -402,25 +415,14 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
402
415
|
}], "account", void 0);
|
|
403
416
|
},
|
|
404
417
|
deleteUserSessions: async (userId) => {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
const sessions = activeSession ? safeJSONParse(activeSession) : [];
|
|
408
|
-
if (!sessions) return;
|
|
409
|
-
for (const session of sessions) await secondaryStorage.delete(session.token);
|
|
410
|
-
await secondaryStorage.delete(`active-sessions-${userId}`);
|
|
411
|
-
if (!options.session?.storeSessionInDatabase || ctx.options.session?.preserveSessionInDatabase) return;
|
|
412
|
-
}
|
|
413
|
-
await deleteManyWithHooks([{
|
|
414
|
-
field: "userId",
|
|
415
|
-
value: userId
|
|
416
|
-
}], "session", void 0);
|
|
418
|
+
await deleteSecondaryStorageSessions(userId);
|
|
419
|
+
if (databaseStoresSessions && !preservesDatabaseSessions) await deleteDatabaseSessions(userId);
|
|
417
420
|
},
|
|
418
421
|
deleteSessions: async (sessionTokens) => {
|
|
419
422
|
if (secondaryStorage) {
|
|
420
423
|
for (const sessionToken of sessionTokens) if (await secondaryStorage.get(sessionToken)) await secondaryStorage.delete(sessionToken);
|
|
421
|
-
if (!options.session?.storeSessionInDatabase || ctx.options.session?.preserveSessionInDatabase) return;
|
|
422
424
|
}
|
|
423
|
-
await deleteManyWithHooks([{
|
|
425
|
+
if (databaseStoresSessions && !preservesDatabaseSessions) await deleteManyWithHooks([{
|
|
424
426
|
field: "token",
|
|
425
427
|
value: sessionTokens,
|
|
426
428
|
operator: "in"
|
|
@@ -14,11 +14,11 @@ declare const nextCookies: () => {
|
|
|
14
14
|
hooks: {
|
|
15
15
|
before: {
|
|
16
16
|
matcher(ctx: import("@better-auth/core").HookEndpointContext): boolean;
|
|
17
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
17
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
18
18
|
}[];
|
|
19
19
|
after: {
|
|
20
20
|
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
21
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
21
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
22
22
|
}[];
|
|
23
23
|
};
|
|
24
24
|
};
|
|
@@ -16,6 +16,20 @@ function toNextJsHandler(auth) {
|
|
|
16
16
|
DELETE: handler
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
let nextHeadersModulePromise;
|
|
20
|
+
/**
|
|
21
|
+
* Cache ESM resolution while leaving the request-scoped `headers()` and
|
|
22
|
+
* `cookies()` calls uncached.
|
|
23
|
+
*
|
|
24
|
+
* @see https://github.com/better-auth/better-auth/issues/10466
|
|
25
|
+
*/
|
|
26
|
+
const loadNextHeadersModule = () => {
|
|
27
|
+
nextHeadersModulePromise ??= import("next/headers.js").catch((error) => {
|
|
28
|
+
nextHeadersModulePromise = void 0;
|
|
29
|
+
throw error;
|
|
30
|
+
});
|
|
31
|
+
return nextHeadersModulePromise;
|
|
32
|
+
};
|
|
19
33
|
const nextCookies = () => {
|
|
20
34
|
let hasWarned = false;
|
|
21
35
|
return {
|
|
@@ -34,7 +48,7 @@ const nextCookies = () => {
|
|
|
34
48
|
if ("_flag" in ctx && ctx._flag === "router") return;
|
|
35
49
|
let headersStore;
|
|
36
50
|
try {
|
|
37
|
-
const { headers } = await
|
|
51
|
+
const { headers } = await loadNextHeadersModule();
|
|
38
52
|
headersStore = await headers();
|
|
39
53
|
} catch {
|
|
40
54
|
return;
|
|
@@ -68,7 +82,7 @@ const nextCookies = () => {
|
|
|
68
82
|
const parsed = parseSetCookieHeader(setCookies);
|
|
69
83
|
let cookieHelper;
|
|
70
84
|
try {
|
|
71
|
-
const { cookies } = await
|
|
85
|
+
const { cookies } = await loadNextHeadersModule();
|
|
72
86
|
cookieHelper = await cookies();
|
|
73
87
|
} catch (error) {
|
|
74
88
|
if (error instanceof Error && (error.message.startsWith("`cookies` was called outside a request scope.") || error.message.includes("Cannot find module"))) return;
|
|
@@ -23,7 +23,7 @@ declare const sveltekitCookies: (getRequestEvent: () => RequestEvent<any, any>)
|
|
|
23
23
|
hooks: {
|
|
24
24
|
after: {
|
|
25
25
|
matcher(): true;
|
|
26
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
26
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
27
27
|
}[];
|
|
28
28
|
};
|
|
29
29
|
};
|
|
@@ -22,7 +22,7 @@ declare const tanstackStartCookies: () => {
|
|
|
22
22
|
hooks: {
|
|
23
23
|
after: {
|
|
24
24
|
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
25
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
25
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
};
|
|
@@ -22,7 +22,7 @@ declare const tanstackStartCookies: () => {
|
|
|
22
22
|
hooks: {
|
|
23
23
|
after: {
|
|
24
24
|
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
25
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
25
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
28
|
};
|
package/dist/package.mjs
CHANGED
|
@@ -59,7 +59,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
59
59
|
hooks: {
|
|
60
60
|
after: {
|
|
61
61
|
matcher(context: import("@better-auth/core").HookEndpointContext): boolean;
|
|
62
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<SessionWithImpersonatedBy[] | undefined
|
|
62
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<SessionWithImpersonatedBy[] | undefined>>;
|
|
63
63
|
}[];
|
|
64
64
|
};
|
|
65
65
|
endpoints: {
|
|
@@ -70,7 +70,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
70
70
|
role: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString>]>;
|
|
71
71
|
}, import("zod/v4/core").$strip>;
|
|
72
72
|
requireHeaders: true;
|
|
73
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
73
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
74
74
|
session: {
|
|
75
75
|
user: UserWithRole;
|
|
76
76
|
session: {
|
|
@@ -84,7 +84,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
84
84
|
userAgent?: string | null | undefined;
|
|
85
85
|
};
|
|
86
86
|
};
|
|
87
|
-
}
|
|
87
|
+
}>>[];
|
|
88
88
|
metadata: {
|
|
89
89
|
openapi: {
|
|
90
90
|
operationId: string;
|
|
@@ -123,7 +123,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
123
123
|
query: import("zod").ZodObject<{
|
|
124
124
|
id: import("zod").ZodString;
|
|
125
125
|
}, import("zod/v4/core").$strip>;
|
|
126
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
126
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
127
127
|
session: {
|
|
128
128
|
user: UserWithRole;
|
|
129
129
|
session: {
|
|
@@ -137,7 +137,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
137
137
|
userAgent?: string | null | undefined;
|
|
138
138
|
};
|
|
139
139
|
};
|
|
140
|
-
}
|
|
140
|
+
}>>[];
|
|
141
141
|
metadata: {
|
|
142
142
|
openapi: {
|
|
143
143
|
operationId: string;
|
|
@@ -214,7 +214,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
214
214
|
userId: import("zod").ZodCoercedString<unknown>;
|
|
215
215
|
data: import("zod").ZodRecord<import("zod").ZodAny, import("zod").ZodAny>;
|
|
216
216
|
}, import("zod/v4/core").$strip>;
|
|
217
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
217
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
218
218
|
session: {
|
|
219
219
|
user: UserWithRole;
|
|
220
220
|
session: {
|
|
@@ -228,7 +228,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
228
228
|
userAgent?: string | null | undefined;
|
|
229
229
|
};
|
|
230
230
|
};
|
|
231
|
-
}
|
|
231
|
+
}>>[];
|
|
232
232
|
metadata: {
|
|
233
233
|
openapi: {
|
|
234
234
|
operationId: string;
|
|
@@ -256,7 +256,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
256
256
|
}, UserWithRole>;
|
|
257
257
|
listUsers: import("better-call").StrictEndpoint<"/admin/list-users", {
|
|
258
258
|
method: "GET";
|
|
259
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
259
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
260
260
|
session: {
|
|
261
261
|
user: UserWithRole;
|
|
262
262
|
session: {
|
|
@@ -270,7 +270,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
270
270
|
userAgent?: string | null | undefined;
|
|
271
271
|
};
|
|
272
272
|
};
|
|
273
|
-
}
|
|
273
|
+
}>>[];
|
|
274
274
|
query: import("zod").ZodObject<{
|
|
275
275
|
searchValue: import("zod").ZodOptional<import("zod").ZodString>;
|
|
276
276
|
searchField: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
@@ -348,7 +348,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
348
348
|
}>;
|
|
349
349
|
listUserSessions: import("better-call").StrictEndpoint<"/admin/list-user-sessions", {
|
|
350
350
|
method: "POST";
|
|
351
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
351
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
352
352
|
session: {
|
|
353
353
|
user: UserWithRole;
|
|
354
354
|
session: {
|
|
@@ -362,7 +362,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
362
362
|
userAgent?: string | null | undefined;
|
|
363
363
|
};
|
|
364
364
|
};
|
|
365
|
-
}
|
|
365
|
+
}>>[];
|
|
366
366
|
body: import("zod").ZodObject<{
|
|
367
367
|
userId: import("zod").ZodCoercedString<unknown>;
|
|
368
368
|
}, import("zod/v4/core").$strip>;
|
|
@@ -401,7 +401,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
401
401
|
body: import("zod").ZodObject<{
|
|
402
402
|
userId: import("zod").ZodCoercedString<unknown>;
|
|
403
403
|
}, import("zod/v4/core").$strip>;
|
|
404
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
404
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
405
405
|
session: {
|
|
406
406
|
user: UserWithRole;
|
|
407
407
|
session: {
|
|
@@ -415,7 +415,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
415
415
|
userAgent?: string | null | undefined;
|
|
416
416
|
};
|
|
417
417
|
};
|
|
418
|
-
}
|
|
418
|
+
}>>[];
|
|
419
419
|
metadata: {
|
|
420
420
|
openapi: {
|
|
421
421
|
operationId: string;
|
|
@@ -450,7 +450,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
450
450
|
banReason: import("zod").ZodOptional<import("zod").ZodString>;
|
|
451
451
|
banExpiresIn: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
452
452
|
}, import("zod/v4/core").$strip>;
|
|
453
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
453
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
454
454
|
session: {
|
|
455
455
|
user: UserWithRole;
|
|
456
456
|
session: {
|
|
@@ -464,7 +464,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
464
464
|
userAgent?: string | null | undefined;
|
|
465
465
|
};
|
|
466
466
|
};
|
|
467
|
-
}
|
|
467
|
+
}>>[];
|
|
468
468
|
metadata: {
|
|
469
469
|
openapi: {
|
|
470
470
|
operationId: string;
|
|
@@ -497,7 +497,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
497
497
|
body: import("zod").ZodObject<{
|
|
498
498
|
userId: import("zod").ZodCoercedString<unknown>;
|
|
499
499
|
}, import("zod/v4/core").$strip>;
|
|
500
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
500
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
501
501
|
session: {
|
|
502
502
|
user: UserWithRole;
|
|
503
503
|
session: {
|
|
@@ -511,7 +511,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
511
511
|
userAgent?: string | null | undefined;
|
|
512
512
|
};
|
|
513
513
|
};
|
|
514
|
-
}
|
|
514
|
+
}>>[];
|
|
515
515
|
metadata: {
|
|
516
516
|
openapi: {
|
|
517
517
|
operationId: string;
|
|
@@ -581,7 +581,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
581
581
|
body: import("zod").ZodObject<{
|
|
582
582
|
sessionToken: import("zod").ZodString;
|
|
583
583
|
}, import("zod/v4/core").$strip>;
|
|
584
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
584
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
585
585
|
session: {
|
|
586
586
|
user: UserWithRole;
|
|
587
587
|
session: {
|
|
@@ -595,7 +595,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
595
595
|
userAgent?: string | null | undefined;
|
|
596
596
|
};
|
|
597
597
|
};
|
|
598
|
-
}
|
|
598
|
+
}>>[];
|
|
599
599
|
metadata: {
|
|
600
600
|
openapi: {
|
|
601
601
|
operationId: string;
|
|
@@ -628,7 +628,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
628
628
|
body: import("zod").ZodObject<{
|
|
629
629
|
userId: import("zod").ZodCoercedString<unknown>;
|
|
630
630
|
}, import("zod/v4/core").$strip>;
|
|
631
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
631
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
632
632
|
session: {
|
|
633
633
|
user: UserWithRole;
|
|
634
634
|
session: {
|
|
@@ -642,7 +642,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
642
642
|
userAgent?: string | null | undefined;
|
|
643
643
|
};
|
|
644
644
|
};
|
|
645
|
-
}
|
|
645
|
+
}>>[];
|
|
646
646
|
metadata: {
|
|
647
647
|
openapi: {
|
|
648
648
|
operationId: string;
|
|
@@ -675,7 +675,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
675
675
|
body: import("zod").ZodObject<{
|
|
676
676
|
userId: import("zod").ZodCoercedString<unknown>;
|
|
677
677
|
}, import("zod/v4/core").$strip>;
|
|
678
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
678
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
679
679
|
session: {
|
|
680
680
|
user: UserWithRole;
|
|
681
681
|
session: {
|
|
@@ -689,7 +689,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
689
689
|
userAgent?: string | null | undefined;
|
|
690
690
|
};
|
|
691
691
|
};
|
|
692
|
-
}
|
|
692
|
+
}>>[];
|
|
693
693
|
metadata: {
|
|
694
694
|
openapi: {
|
|
695
695
|
operationId: string;
|
|
@@ -723,7 +723,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
723
723
|
newPassword: import("zod").ZodString;
|
|
724
724
|
userId: import("zod").ZodCoercedString<unknown>;
|
|
725
725
|
}, import("zod/v4/core").$strip>;
|
|
726
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
726
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
727
727
|
session: {
|
|
728
728
|
user: UserWithRole;
|
|
729
729
|
session: {
|
|
@@ -737,7 +737,7 @@ declare const admin: <O extends AdminOptions>(options?: O | undefined) => {
|
|
|
737
737
|
userAgent?: string | null | undefined;
|
|
738
738
|
};
|
|
739
739
|
};
|
|
740
|
-
}
|
|
740
|
+
}>>[];
|
|
741
741
|
metadata: {
|
|
742
742
|
openapi: {
|
|
743
743
|
operationId: string;
|
|
@@ -52,7 +52,7 @@ declare const anonymous: (options?: AnonymousOptions | undefined) => {
|
|
|
52
52
|
}>;
|
|
53
53
|
deleteAnonymousUser: import("better-call").StrictEndpoint<"/delete-anonymous-user", {
|
|
54
54
|
method: "POST";
|
|
55
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
55
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
56
56
|
session: {
|
|
57
57
|
session: Record<string, any> & {
|
|
58
58
|
id: string;
|
|
@@ -74,7 +74,7 @@ declare const anonymous: (options?: AnonymousOptions | undefined) => {
|
|
|
74
74
|
image?: string | null | undefined;
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
|
-
}
|
|
77
|
+
}>>[];
|
|
78
78
|
metadata: {
|
|
79
79
|
openapi: {
|
|
80
80
|
description: string;
|
|
@@ -136,7 +136,7 @@ declare const anonymous: (options?: AnonymousOptions | undefined) => {
|
|
|
136
136
|
hooks: {
|
|
137
137
|
after: {
|
|
138
138
|
matcher(ctx: import("@better-auth/core").HookEndpointContext): boolean;
|
|
139
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
139
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
140
140
|
}[];
|
|
141
141
|
};
|
|
142
142
|
options: AnonymousOptions | undefined;
|
|
@@ -154,7 +154,6 @@ const anonymous = (options) => {
|
|
|
154
154
|
const newSessionIsAnonymous = Boolean(newSessionUser?.isAnonymous);
|
|
155
155
|
if (options?.disableDeleteAnonymousUser || isSameUser || newSessionIsAnonymous) return;
|
|
156
156
|
try {
|
|
157
|
-
await ctx.context.internalAdapter.deleteUserSessions(session.user.id);
|
|
158
157
|
await ctx.context.internalAdapter.deleteUser(session.user.id);
|
|
159
158
|
} catch (error) {
|
|
160
159
|
ctx.context.logger.error("Failed to clean up anonymous user during post-link cleanup", {
|
|
@@ -25,15 +25,15 @@ declare const bearer: (options?: BearerOptions | undefined) => {
|
|
|
25
25
|
hooks: {
|
|
26
26
|
before: {
|
|
27
27
|
matcher(context: import("@better-auth/core").HookEndpointContext): boolean;
|
|
28
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
28
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
29
29
|
context: {
|
|
30
30
|
headers: Headers;
|
|
31
31
|
};
|
|
32
|
-
} | undefined
|
|
32
|
+
} | undefined>>;
|
|
33
33
|
}[];
|
|
34
34
|
after: {
|
|
35
35
|
matcher(context: import("@better-auth/core").HookEndpointContext): true;
|
|
36
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
36
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
37
37
|
}[];
|
|
38
38
|
};
|
|
39
39
|
options: BearerOptions | undefined;
|
|
@@ -24,7 +24,7 @@ declare const customSession: <Returns extends Record<string, any>, O extends Bet
|
|
|
24
24
|
hooks: {
|
|
25
25
|
after: {
|
|
26
26
|
matcher: (ctx: import("@better-auth/core").HookEndpointContext) => boolean;
|
|
27
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<Awaited<Returns>[] | undefined
|
|
27
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<Awaited<Returns>[] | undefined>>;
|
|
28
28
|
}[];
|
|
29
29
|
};
|
|
30
30
|
endpoints: {
|
|
@@ -24,7 +24,7 @@ declare const emailOTP: (options: EmailOTPOptions) => {
|
|
|
24
24
|
endpoints: {
|
|
25
25
|
sendVerificationOTP: import("better-call").StrictEndpoint<"/email-otp/send-verification-otp", {
|
|
26
26
|
method: "POST";
|
|
27
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
27
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
28
28
|
body: import("zod").ZodObject<{
|
|
29
29
|
email: import("zod").ZodString;
|
|
30
30
|
type: import("zod").ZodEnum<{
|
|
@@ -385,7 +385,7 @@ declare const emailOTP: (options: EmailOTPOptions) => {
|
|
|
385
385
|
newEmail: import("zod").ZodString;
|
|
386
386
|
otp: import("zod").ZodOptional<import("zod").ZodString>;
|
|
387
387
|
}, import("zod/v4/core").$strip>;
|
|
388
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
388
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
389
389
|
session: {
|
|
390
390
|
session: Record<string, any> & {
|
|
391
391
|
id: string;
|
|
@@ -407,7 +407,7 @@ declare const emailOTP: (options: EmailOTPOptions) => {
|
|
|
407
407
|
image?: string | null | undefined;
|
|
408
408
|
};
|
|
409
409
|
};
|
|
410
|
-
}
|
|
410
|
+
}>>[];
|
|
411
411
|
metadata: {
|
|
412
412
|
openapi: {
|
|
413
413
|
operationId: string;
|
|
@@ -440,7 +440,7 @@ declare const emailOTP: (options: EmailOTPOptions) => {
|
|
|
440
440
|
newEmail: import("zod").ZodString;
|
|
441
441
|
otp: import("zod").ZodString;
|
|
442
442
|
}, import("zod/v4/core").$strip>;
|
|
443
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
443
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
444
444
|
session: {
|
|
445
445
|
session: Record<string, any> & {
|
|
446
446
|
id: string;
|
|
@@ -462,7 +462,7 @@ declare const emailOTP: (options: EmailOTPOptions) => {
|
|
|
462
462
|
image?: string | null | undefined;
|
|
463
463
|
};
|
|
464
464
|
};
|
|
465
|
-
}
|
|
465
|
+
}>>[];
|
|
466
466
|
metadata: {
|
|
467
467
|
openapi: {
|
|
468
468
|
operationId: string;
|
|
@@ -493,7 +493,7 @@ declare const emailOTP: (options: EmailOTPOptions) => {
|
|
|
493
493
|
hooks: {
|
|
494
494
|
after: {
|
|
495
495
|
matcher(context: import("@better-auth/core").HookEndpointContext): boolean;
|
|
496
|
-
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void
|
|
496
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
497
497
|
}[];
|
|
498
498
|
};
|
|
499
499
|
rateLimit: ({
|
|
@@ -56,7 +56,7 @@ const emailOTP = (options) => {
|
|
|
56
56
|
if (email) {
|
|
57
57
|
const otp = opts.generateOTP({
|
|
58
58
|
email,
|
|
59
|
-
type:
|
|
59
|
+
type: "email-verification"
|
|
60
60
|
}, ctx) || defaultOTPGenerator(opts);
|
|
61
61
|
const storedOTP = await storeOTP(ctx, opts, otp);
|
|
62
62
|
await ctx.context.internalAdapter.createVerificationValue({
|
|
@@ -235,7 +235,6 @@ const checkVerificationOTP = (opts) => createAuthEndpoint("/email-otp/check-veri
|
|
|
235
235
|
}, async (ctx) => {
|
|
236
236
|
const email = ctx.body.email.toLowerCase();
|
|
237
237
|
if (!z.email().safeParse(email).success) throw APIError$1.from("BAD_REQUEST", BASE_ERROR_CODES.INVALID_EMAIL);
|
|
238
|
-
if (!await ctx.context.internalAdapter.findUserByEmail(email)) throw APIError$1.from("BAD_REQUEST", BASE_ERROR_CODES.USER_NOT_FOUND);
|
|
239
238
|
const identifier = toOTPIdentifier(ctx.body.type, email);
|
|
240
239
|
const verificationValue = await ctx.context.internalAdapter.findVerificationValue(identifier);
|
|
241
240
|
if (!verificationValue) throw APIError$1.from("BAD_REQUEST", EMAIL_OTP_ERROR_CODES.INVALID_OTP);
|
|
@@ -253,6 +252,12 @@ const checkVerificationOTP = (opts) => createAuthEndpoint("/email-otp/check-veri
|
|
|
253
252
|
await ctx.context.internalAdapter.updateVerificationByIdentifier(identifier, { value: `${otpValue}:${parseInt(attempts || "0") + 1}` });
|
|
254
253
|
throw APIError$1.from("BAD_REQUEST", EMAIL_OTP_ERROR_CODES.INVALID_OTP);
|
|
255
254
|
}
|
|
255
|
+
if (!await ctx.context.internalAdapter.findUserByEmail(email))
|
|
256
|
+
/**
|
|
257
|
+
* safe to leak the existence of a user, given the user has already the OTP from the
|
|
258
|
+
* email
|
|
259
|
+
*/
|
|
260
|
+
throw APIError$1.from("BAD_REQUEST", BASE_ERROR_CODES.USER_NOT_FOUND);
|
|
256
261
|
return ctx.json({ success: true });
|
|
257
262
|
});
|
|
258
263
|
const verifyEmailOTPBodySchema = z.object({
|
|
@@ -574,13 +579,13 @@ const resetPasswordEmailOTP = (opts) => createAuthEndpoint("/email-otp/reset-pas
|
|
|
574
579
|
} }
|
|
575
580
|
}, async (ctx) => {
|
|
576
581
|
const email = ctx.body.email.toLowerCase();
|
|
577
|
-
await atomicVerifyOTP(ctx, opts, toOTPIdentifier("forget-password", email), ctx.body.otp);
|
|
578
|
-
const user = await ctx.context.internalAdapter.findUserByEmail(email, { includeAccounts: true });
|
|
579
|
-
if (!user) throw APIError$1.from("BAD_REQUEST", BASE_ERROR_CODES.USER_NOT_FOUND);
|
|
580
582
|
const minPasswordLength = ctx.context.password.config.minPasswordLength;
|
|
581
583
|
if (ctx.body.password.length < minPasswordLength) throw APIError$1.from("BAD_REQUEST", BASE_ERROR_CODES.PASSWORD_TOO_SHORT);
|
|
582
584
|
const maxPasswordLength = ctx.context.password.config.maxPasswordLength;
|
|
583
585
|
if (ctx.body.password.length > maxPasswordLength) throw APIError$1.from("BAD_REQUEST", BASE_ERROR_CODES.PASSWORD_TOO_LONG);
|
|
586
|
+
await atomicVerifyOTP(ctx, opts, toOTPIdentifier("forget-password", email), ctx.body.otp);
|
|
587
|
+
const user = await ctx.context.internalAdapter.findUserByEmail(email, { includeAccounts: true });
|
|
588
|
+
if (!user) throw APIError$1.from("BAD_REQUEST", BASE_ERROR_CODES.USER_NOT_FOUND);
|
|
584
589
|
const passwordHash = await ctx.context.password.hash(ctx.body.password);
|
|
585
590
|
if (!user.accounts?.find((account) => account.providerId === "credential")) await ctx.context.internalAdapter.createAccount({
|
|
586
591
|
userId: user.user.id,
|
|
@@ -123,7 +123,7 @@ declare const genericOAuth: (options: GenericOAuthOptions) => {
|
|
|
123
123
|
scopes: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
124
124
|
errorCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
|
|
125
125
|
}, import("zod/v4/core").$strip>;
|
|
126
|
-
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
126
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
127
127
|
session: {
|
|
128
128
|
session: Record<string, any> & {
|
|
129
129
|
id: string;
|
|
@@ -145,7 +145,7 @@ declare const genericOAuth: (options: GenericOAuthOptions) => {
|
|
|
145
145
|
image?: string | null | undefined;
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
|
-
}
|
|
148
|
+
}>>[];
|
|
149
149
|
metadata: {
|
|
150
150
|
openapi: {
|
|
151
151
|
description: string;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import { getCurrentAdapter } from "@better-auth/core/context";
|
|
1
2
|
//#region src/plugins/jwt/adapter.ts
|
|
2
|
-
const getJwksAdapter = (
|
|
3
|
+
const getJwksAdapter = (baseAdapter, options) => {
|
|
3
4
|
return {
|
|
4
5
|
getAllKeys: async (ctx) => {
|
|
5
6
|
if (options?.adapter?.getJwks) return await options.adapter.getJwks(ctx);
|
|
6
|
-
return await
|
|
7
|
+
return await (await getCurrentAdapter(baseAdapter)).findMany({ model: "jwks" });
|
|
7
8
|
},
|
|
8
9
|
getLatestKey: async (ctx) => {
|
|
9
10
|
if (options?.adapter?.getJwks) return (await options.adapter.getJwks(ctx))?.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())[0];
|
|
10
|
-
return (await
|
|
11
|
+
return (await (await getCurrentAdapter(baseAdapter)).findMany({ model: "jwks" }))?.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())[0];
|
|
11
12
|
},
|
|
12
13
|
createJwk: async (ctx, webKey) => {
|
|
13
14
|
if (options?.adapter?.createJwk) return await options.adapter.createJwk(webKey, ctx);
|
|
14
|
-
return await
|
|
15
|
+
return await (await getCurrentAdapter(baseAdapter)).create({
|
|
15
16
|
model: "jwks",
|
|
16
17
|
data: {
|
|
17
18
|
...webKey,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions } from "./types.mjs";
|
|
2
2
|
import { jwt } from "./index.mjs";
|
|
3
|
+
import { BetterAuthClientOptions, ClientFetchOption, ClientStore } from "@better-auth/core";
|
|
3
4
|
import { JSONWebKeySet } from "jose";
|
|
5
|
+
import { BetterFetch } from "@better-fetch/fetch";
|
|
4
6
|
//#region src/plugins/jwt/client.d.ts
|
|
5
7
|
interface JwtClientOptions {
|
|
6
8
|
jwks?: {
|
|
@@ -20,8 +22,8 @@ declare const jwtClient: (options?: JwtClientOptions) => {
|
|
|
20
22
|
pathMethods: {
|
|
21
23
|
[x: string]: "GET";
|
|
22
24
|
};
|
|
23
|
-
getActions: ($fetch:
|
|
24
|
-
jwks: (fetchOptions?:
|
|
25
|
+
getActions: ($fetch: BetterFetch, _$store: ClientStore, _options: BetterAuthClientOptions | undefined) => {
|
|
26
|
+
jwks: (fetchOptions?: ClientFetchOption) => Promise<{
|
|
25
27
|
data: null;
|
|
26
28
|
error: {
|
|
27
29
|
message?: string | undefined;
|