better-auth 1.6.22 → 1.6.24
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/adapters/index.d.mts +1 -6
- package/dist/api/dispatch.d.mts +0 -1
- package/dist/api/index.d.mts +476 -478
- package/dist/api/middlewares/authorization.d.mts +12 -8
- package/dist/api/middlewares/authorization.mjs +2 -1
- package/dist/api/middlewares/index.d.mts +2 -1
- package/dist/api/middlewares/origin-check.d.mts +3 -5
- package/dist/api/routes/account.d.mts +10 -13
- package/dist/api/routes/account.mjs +35 -7
- package/dist/api/routes/callback.d.mts +1 -3
- package/dist/api/routes/callback.mjs +4 -0
- package/dist/api/routes/email-verification.d.mts +4 -8
- package/dist/api/routes/email-verification.mjs +15 -2
- package/dist/api/routes/error.d.mts +1 -3
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +1 -3
- package/dist/api/routes/password.d.mts +7 -9
- package/dist/api/routes/password.mjs +14 -1
- package/dist/api/routes/session.d.mts +22 -24
- package/dist/api/routes/session.mjs +5 -1
- package/dist/api/routes/sign-in.d.mts +3 -5
- package/dist/api/routes/sign-in.mjs +84 -2
- package/dist/api/routes/sign-out.d.mts +1 -3
- package/dist/api/routes/sign-up.d.mts +3 -4
- package/dist/api/routes/sign-up.mjs +3 -2
- package/dist/api/routes/update-session.d.mts +3 -4
- package/dist/api/routes/update-user.d.mts +13 -14
- package/dist/api/routes/update-user.mjs +26 -1
- package/dist/auth/full.d.mts +1 -1
- package/dist/auth/minimal.d.mts +1 -1
- package/dist/client/config.d.mts +12 -14
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +0 -1
- package/dist/client/index.d.mts +6 -5
- package/dist/client/lynx/index.d.mts +4 -5
- package/dist/client/lynx/lynx-store.d.mts +1 -2
- package/dist/client/parser.d.mts +7 -3
- package/dist/client/path-to-object.d.mts +3 -4
- package/dist/client/plugins/index.d.mts +2 -1
- package/dist/client/plugins/infer-plugin.d.mts +0 -1
- package/dist/client/query.d.mts +0 -1
- package/dist/client/query.mjs +38 -20
- package/dist/client/react/index.d.mts +4 -5
- package/dist/client/react/react-store.d.mts +1 -2
- package/dist/client/session-refresh.d.mts +0 -1
- package/dist/client/solid/index.d.mts +5 -6
- package/dist/client/svelte/index.d.mts +5 -6
- package/dist/client/types.d.mts +2 -2
- package/dist/client/vanilla.d.mts +2 -3
- package/dist/client/vue/index.d.mts +5 -6
- package/dist/context/create-context.mjs +3 -3
- package/dist/context/helpers.mjs +2 -2
- package/dist/cookies/cookie-utils.d.mts +1 -1
- package/dist/cookies/index.d.mts +6 -7
- package/dist/cookies/index.mjs +4 -0
- package/dist/cookies/session-store.d.mts +1 -0
- package/dist/cookies/session-store.mjs +6 -1
- package/dist/crypto/index.d.mts +2 -9
- package/dist/crypto/jwt.d.mts +0 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/db/adapter-base.d.mts +0 -1
- package/dist/db/adapter-kysely.d.mts +0 -1
- package/dist/db/field-converter.d.mts +0 -1
- package/dist/db/field.d.mts +9 -10
- package/dist/db/get-migration.d.mts +0 -1
- package/dist/db/get-migration.mjs +8 -4
- package/dist/db/get-schema.d.mts +0 -1
- package/dist/db/internal-adapter.d.mts +0 -1
- package/dist/db/internal-adapter.mjs +61 -1
- package/dist/db/revoke-unproven-account-access.d.mts +0 -1
- package/dist/db/schema.d.mts +2 -2
- package/dist/db/to-zod.d.mts +3 -7
- package/dist/db/with-hooks.d.mts +0 -1
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +4 -7
- package/dist/integrations/node.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +2 -9
- package/dist/integrations/tanstack-start-solid.d.mts +2 -5
- package/dist/integrations/tanstack-start.d.mts +2 -5
- package/dist/oauth2/link-account.d.mts +1 -1
- package/dist/oauth2/state.d.mts +0 -1
- package/dist/oauth2/utils.d.mts +0 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +0 -1
- package/dist/plugins/access/types.d.mts +4 -5
- package/dist/plugins/additional-fields/client.d.mts +0 -1
- package/dist/plugins/admin/access/statement.d.mts +1 -0
- package/dist/plugins/admin/admin.d.mts +120 -125
- package/dist/plugins/admin/client.d.mts +30 -30
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +23 -25
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/routes.mjs +9 -0
- package/dist/plugins/admin/schema.d.mts +1 -1
- package/dist/plugins/admin/types.d.mts +3 -2
- package/dist/plugins/anonymous/client.d.mts +9 -11
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +8 -10
- package/dist/plugins/anonymous/index.d.mts +14 -18
- package/dist/plugins/anonymous/types.d.mts +1 -1
- package/dist/plugins/bearer/index.d.mts +4 -7
- package/dist/plugins/captcha/index.d.mts +5 -8
- package/dist/plugins/captcha/types.d.mts +0 -1
- package/dist/plugins/custom-session/client.d.mts +0 -1
- package/dist/plugins/custom-session/index.d.mts +7 -12
- package/dist/plugins/device-authorization/client.d.mts +0 -1
- package/dist/plugins/device-authorization/index.d.mts +19 -22
- package/dist/plugins/email-otp/client.d.mts +4 -6
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +3 -5
- package/dist/plugins/email-otp/index.d.mts +67 -73
- package/dist/plugins/email-otp/routes.mjs +2 -0
- package/dist/plugins/email-otp/types.d.mts +0 -1
- package/dist/plugins/generic-oauth/client.d.mts +11 -11
- package/dist/plugins/generic-oauth/client.mjs +1 -1
- package/dist/plugins/generic-oauth/error-codes.d.mts +8 -10
- package/dist/plugins/generic-oauth/index.d.mts +41 -44
- package/dist/plugins/generic-oauth/index.mjs +2 -1
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +3 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/line.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/okta.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/slack.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +28 -0
- package/dist/plugins/generic-oauth/providers/yandex.mjs +60 -0
- package/dist/plugins/generic-oauth/routes.mjs +14 -0
- package/dist/plugins/generic-oauth/types.d.mts +1 -2
- package/dist/plugins/haveibeenpwned/index.d.mts +3 -6
- package/dist/plugins/index.d.mts +5 -1
- package/dist/plugins/index.mjs +2 -1
- package/dist/plugins/jwt/client.d.mts +2 -4
- package/dist/plugins/jwt/index.d.mts +8 -11
- package/dist/plugins/jwt/sign.d.mts +2 -2
- package/dist/plugins/jwt/types.d.mts +1 -1
- package/dist/plugins/jwt/utils.d.mts +2 -4
- package/dist/plugins/jwt/verify.d.mts +0 -1
- package/dist/plugins/last-login-method/client.mjs +13 -0
- package/dist/plugins/last-login-method/index.d.mts +11 -5
- package/dist/plugins/last-login-method/index.mjs +8 -0
- package/dist/plugins/magic-link/client.d.mts +0 -1
- package/dist/plugins/magic-link/index.d.mts +4 -5
- package/dist/plugins/magic-link/index.mjs +32 -1
- package/dist/plugins/mcp/authorize.mjs +12 -0
- package/dist/plugins/mcp/client/adapters.d.mts +0 -1
- package/dist/plugins/mcp/client/index.d.mts +2 -0
- package/dist/plugins/mcp/client/index.mjs +36 -11
- package/dist/plugins/mcp/index.d.mts +10 -11
- package/dist/plugins/multi-session/client.d.mts +2 -4
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +1 -3
- package/dist/plugins/multi-session/index.d.mts +7 -11
- package/dist/plugins/multi-session/index.mjs +45 -0
- package/dist/plugins/oauth-popup/client.d.mts +6 -12
- package/dist/plugins/oauth-popup/client.mjs +5 -3
- package/dist/plugins/oauth-popup/error-codes.d.mts +4 -6
- package/dist/plugins/oauth-popup/index.d.mts +8 -12
- package/dist/plugins/oauth-popup/index.mjs +1 -1
- package/dist/plugins/oauth-popup/types.d.mts +1 -2
- package/dist/plugins/oauth-proxy/index.d.mts +6 -9
- package/dist/plugins/oauth-proxy/index.mjs +2 -2
- package/dist/plugins/oidc-provider/authorize.mjs +9 -0
- package/dist/plugins/oidc-provider/client.d.mts +1 -2
- package/dist/plugins/oidc-provider/index.d.mts +15 -17
- package/dist/plugins/oidc-provider/index.mjs +26 -2
- package/dist/plugins/oidc-provider/schema.d.mts +0 -1
- package/dist/plugins/oidc-provider/schema.mjs +37 -0
- package/dist/plugins/oidc-provider/types.d.mts +1 -1
- package/dist/plugins/one-tap/client.d.mts +3 -6
- package/dist/plugins/one-tap/client.mjs +3 -0
- package/dist/plugins/one-tap/index.d.mts +1 -3
- package/dist/plugins/one-tap/index.mjs +5 -0
- package/dist/plugins/one-time-token/client.d.mts +1 -2
- package/dist/plugins/one-time-token/index.d.mts +5 -6
- package/dist/plugins/one-time-token/index.mjs +30 -0
- package/dist/plugins/open-api/generator.d.mts +0 -1
- package/dist/plugins/open-api/generator.mjs +81 -5
- package/dist/plugins/open-api/index.d.mts +3 -5
- package/dist/plugins/organization/access/statement.d.mts +1 -0
- package/dist/plugins/organization/adapter.d.mts +56 -82
- package/dist/plugins/organization/adapter.mjs +17 -3
- package/dist/plugins/organization/client.d.mts +106 -105
- package/dist/plugins/organization/client.mjs +7 -4
- package/dist/plugins/organization/error-codes.d.mts +59 -61
- package/dist/plugins/organization/has-permission.d.mts +0 -1
- package/dist/plugins/organization/has-permission.mjs +1 -1
- package/dist/plugins/organization/index.d.mts +1 -1
- package/dist/plugins/organization/organization.d.mts +7 -7
- package/dist/plugins/organization/organization.mjs +434 -1
- package/dist/plugins/organization/permission.d.mts +2 -2
- package/dist/plugins/organization/routes/crud-access-control.d.mts +17 -17
- package/dist/plugins/organization/routes/crud-invites.d.mts +53 -54
- package/dist/plugins/organization/routes/crud-invites.mjs +1 -1
- package/dist/plugins/organization/routes/crud-members.d.mts +44 -46
- package/dist/plugins/organization/routes/crud-members.mjs +4 -1
- package/dist/plugins/organization/routes/crud-org.d.mts +47 -48
- package/dist/plugins/organization/routes/crud-org.mjs +2 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +50 -51
- package/dist/plugins/organization/schema.d.mts +4 -4
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -16
- package/dist/plugins/phone-number/client.d.mts +13 -15
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +12 -14
- package/dist/plugins/phone-number/index.d.mts +41 -47
- package/dist/plugins/phone-number/routes.mjs +15 -0
- package/dist/plugins/phone-number/types.d.mts +1 -1
- package/dist/plugins/siwe/client.d.mts +0 -1
- package/dist/plugins/siwe/index.d.mts +4 -5
- package/dist/plugins/test-utils/index.d.mts +2 -4
- package/dist/plugins/test-utils/types.d.mts +1 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +4 -6
- package/dist/plugins/two-factor/backup-codes/index.mjs +52 -1
- package/dist/plugins/two-factor/client.d.mts +12 -15
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +10 -12
- package/dist/plugins/two-factor/index.d.mts +27 -31
- package/dist/plugins/two-factor/index.mjs +30 -0
- package/dist/plugins/two-factor/otp/index.d.mts +2 -4
- package/dist/plugins/two-factor/otp/index.mjs +42 -1
- package/dist/plugins/two-factor/totp/index.d.mts +4 -6
- package/dist/plugins/two-factor/totp/index.mjs +47 -0
- package/dist/plugins/two-factor/types.d.mts +1 -1
- package/dist/plugins/username/client.d.mts +9 -11
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +8 -10
- package/dist/plugins/username/index.d.mts +17 -22
- package/dist/plugins/username/schema.d.mts +3 -5
- package/dist/state.d.mts +0 -1
- package/dist/state.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +5 -3
- package/dist/test-utils/test-instance.mjs +4 -1
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +1 -2
- package/dist/types/auth.d.mts +0 -1
- package/dist/types/helper.d.mts +5 -5
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +0 -1
- package/dist/types/plugins.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/request.mjs +23 -0
- package/dist/utils/url.d.mts +0 -1
- package/package.json +10 -10
|
@@ -55,7 +55,11 @@ const map = {
|
|
|
55
55
|
},
|
|
56
56
|
sqlite: {
|
|
57
57
|
string: ["TEXT"],
|
|
58
|
-
number: [
|
|
58
|
+
number: [
|
|
59
|
+
"INTEGER",
|
|
60
|
+
"REAL",
|
|
61
|
+
"BIGINT"
|
|
62
|
+
],
|
|
59
63
|
boolean: ["INTEGER", "BOOLEAN"],
|
|
60
64
|
date: ["DATE", "INTEGER"],
|
|
61
65
|
json: ["TEXT"]
|
|
@@ -314,9 +318,9 @@ async function getMigrations(config) {
|
|
|
314
318
|
else col = col.defaultTo(sql`CURRENT_TIMESTAMP`);
|
|
315
319
|
return col;
|
|
316
320
|
});
|
|
317
|
-
if (field.index) {
|
|
318
|
-
const builder = db.schema.createIndex(`${table.table}_${fieldName}
|
|
319
|
-
deferredIndexes.push(
|
|
321
|
+
if (field.index && !field.unique) {
|
|
322
|
+
const builder = db.schema.createIndex(`${table.table}_${fieldName}_idx`).on(table.table).columns([fieldName]);
|
|
323
|
+
deferredIndexes.push(builder);
|
|
320
324
|
}
|
|
321
325
|
}
|
|
322
326
|
migrations.push(dbT);
|
package/dist/db/get-schema.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { DatabaseHooksEntry } from "./with-hooks.mjs";
|
|
|
2
2
|
import { AuthContext, BetterAuthOptions, InternalAdapter } from "@better-auth/core";
|
|
3
3
|
import { InternalLogger } from "@better-auth/core/env";
|
|
4
4
|
import { DBAdapter } from "@better-auth/core/db/adapter";
|
|
5
|
-
|
|
6
5
|
//#region src/db/internal-adapter.d.ts
|
|
7
6
|
declare const createInternalAdapter: (adapter: DBAdapter<BetterAuthOptions>, ctx: {
|
|
8
7
|
options: Omit<BetterAuthOptions, "logger">;
|
|
@@ -177,6 +177,11 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
177
177
|
ipAddress: headers ? getIp(headers, options) || "" : "",
|
|
178
178
|
userAgent: headers?.get("user-agent") || "",
|
|
179
179
|
...rest,
|
|
180
|
+
/**
|
|
181
|
+
* If the user doesn't want to be remembered
|
|
182
|
+
* set the session to expire in 1 day.
|
|
183
|
+
* The cookie will be set to expire at the end of the session
|
|
184
|
+
*/
|
|
180
185
|
expiresAt: dontRememberMe ? getDate(3600 * 24, "sec") : getDate(sessionExpiration, "sec"),
|
|
181
186
|
userId,
|
|
182
187
|
token: generateId(32),
|
|
@@ -385,6 +390,11 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
385
390
|
value: userId
|
|
386
391
|
}], "account", void 0);
|
|
387
392
|
},
|
|
393
|
+
/**
|
|
394
|
+
* Delete an account by its primary key.
|
|
395
|
+
*
|
|
396
|
+
* @param id - The account row's primary key (the `id` column, not the `accountId` column).
|
|
397
|
+
*/
|
|
388
398
|
deleteAccount: async (id) => {
|
|
389
399
|
await deleteWithHooks([{
|
|
390
400
|
field: "id",
|
|
@@ -637,6 +647,31 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
637
647
|
value: storedIdentifier
|
|
638
648
|
}], "verification", void 0);
|
|
639
649
|
},
|
|
650
|
+
/**
|
|
651
|
+
* Atomically consume a single-use verification row by `identifier` and
|
|
652
|
+
* return it. The first concurrent caller receives the latest row for the
|
|
653
|
+
* identifier; every other caller racing against it receives `null`.
|
|
654
|
+
*
|
|
655
|
+
* Race-safe replacement for the `findVerificationValue` then
|
|
656
|
+
* `deleteVerificationByIdentifier` pair. Callers MUST gate any state
|
|
657
|
+
* change (issue session, mint token, change password) on a non-null
|
|
658
|
+
* return value, because consuming one row invalidates the whole
|
|
659
|
+
* identifier and stale rows cannot be replayed.
|
|
660
|
+
*
|
|
661
|
+
* Rows past their `expiresAt` are treated as already invalid: the row
|
|
662
|
+
* is still deleted (so it cannot be replayed later) but `null` is
|
|
663
|
+
* returned. Callers do not need their own `expiresAt` gate.
|
|
664
|
+
*
|
|
665
|
+
* The secondary-storage-only path (`storeInDatabase: false`) is atomic
|
|
666
|
+
* only when the configured storage implements `getAndDelete`; otherwise
|
|
667
|
+
* it falls back to an in-process lock around `get` then `delete` and
|
|
668
|
+
* warns once, since that fallback cannot coordinate across processes.
|
|
669
|
+
*
|
|
670
|
+
* FIXME(consume-atomic): make `SecondaryStorage.getAndDelete` required
|
|
671
|
+
* in the next breaking release, or require database-backed verification
|
|
672
|
+
* storage for security-sensitive consume paths, so the non-atomic
|
|
673
|
+
* fallback can be removed entirely.
|
|
674
|
+
*/
|
|
640
675
|
consumeVerificationValue: async (identifier) => {
|
|
641
676
|
const storageOption = getStorageOption(identifier, options.verification?.storeIdentifier);
|
|
642
677
|
const storedIdentifier = await processIdentifier(identifier, storageOption);
|
|
@@ -661,7 +696,8 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
661
696
|
logger.warn("Secondary storage does not implement `getAndDelete`, so single-use verification values cannot be consumed atomically across processes. Implement `getAndDelete` or use database-backed verification storage to guarantee single use.");
|
|
662
697
|
}
|
|
663
698
|
return withVerificationConsumeLock(key, async () => {
|
|
664
|
-
const
|
|
699
|
+
const raw = await secondaryStorage.get(key);
|
|
700
|
+
const parsed = hydrateCachedVerification(raw);
|
|
665
701
|
if (!parsed) return null;
|
|
666
702
|
await secondaryStorage.delete(key);
|
|
667
703
|
return parsed;
|
|
@@ -719,6 +755,30 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
719
755
|
if (!consumed || consumed.expiresAt < /* @__PURE__ */ new Date()) return null;
|
|
720
756
|
return consumed;
|
|
721
757
|
},
|
|
758
|
+
/**
|
|
759
|
+
* First-writer-wins create keyed by a deterministic primary key derived
|
|
760
|
+
* from `identifier`. Returns `true` when this caller created the row and
|
|
761
|
+
* `false` when a row for the same identifier already existed.
|
|
762
|
+
*
|
|
763
|
+
* The dual of `consumeVerificationValue`: where consume races to delete a
|
|
764
|
+
* marker exactly once, reserve races to create a marker exactly once. Use
|
|
765
|
+
* it for replay tombstones (a SAML assertion id, a JWT `jti`) where the
|
|
766
|
+
* first caller wins and every later caller must observe that the marker is
|
|
767
|
+
* already taken.
|
|
768
|
+
*
|
|
769
|
+
* The `verification.identifier` column is non-unique, so uniqueness comes
|
|
770
|
+
* from a deterministic primary key (`SHA-256` of `reserve:<identifier>`).
|
|
771
|
+
* The database path is atomic: the primary key turns the INSERT into the
|
|
772
|
+
* first-writer-wins gate, and a duplicate is detected portably by
|
|
773
|
+
* re-reading the row rather than matching adapter-specific errors. The
|
|
774
|
+
* secondary-storage-only path has no primary key to enforce uniqueness, so
|
|
775
|
+
* it is best-effort under concurrency.
|
|
776
|
+
*
|
|
777
|
+
* The atomic guarantee requires the configured adapter to reject a
|
|
778
|
+
* duplicate primary key on insert, which every real database enforces. The
|
|
779
|
+
* in-memory adapter does not enforce primary-key uniqueness, so reservation
|
|
780
|
+
* is best-effort there (it is intended for development and tests).
|
|
781
|
+
*/
|
|
722
782
|
reserveVerificationValue: async (data) => {
|
|
723
783
|
const reservationId = base64Url.encode(new Uint8Array(await createHash("SHA-256").digest(new TextEncoder().encode("reserve:" + data.identifier))), { padding: false });
|
|
724
784
|
const storageOption = getStorageOption(data.identifier, options.verification?.storeIdentifier);
|
package/dist/db/schema.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Account, Session as Session$1, User as User$1 } from "../types/models.mjs";
|
|
2
|
+
import "../types/index.mjs";
|
|
2
3
|
import { BetterAuthOptions } from "@better-auth/core";
|
|
3
4
|
import { BetterAuthPluginDBSchema, DBFieldAttribute } from "@better-auth/core/db";
|
|
4
|
-
|
|
5
5
|
//#region src/db/schema.d.ts
|
|
6
6
|
declare function parseUserOutput<T extends User$1>(options: BetterAuthOptions, user: T): T;
|
|
7
7
|
/**
|
|
@@ -57,6 +57,6 @@ declare function mergeSchema<S extends BetterAuthPluginDBSchema>(schema: S, newS
|
|
|
57
57
|
fields?: {
|
|
58
58
|
[P: string]: string;
|
|
59
59
|
} | undefined;
|
|
60
|
-
} | undefined } | undefined): S;
|
|
60
|
+
} | undefined; } | undefined): S;
|
|
61
61
|
//#endregion
|
|
62
62
|
export { buildSyntheticUserOutput, getSessionDefaultFields, mergeSchema, parseAccountInput, parseAccountOutput, parseAdditionalUserInput, parseAdditionalUserInputFromProviderProfile, parseInputData, parseSessionInput, parseSessionOutput, parseUserInput, parseUserOutput };
|
package/dist/db/to-zod.d.mts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { DBFieldAttribute } from "@better-auth/core/db";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
-
|
|
4
3
|
//#region src/db/to-zod.d.ts
|
|
5
|
-
declare function toZodSchema<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean>({
|
|
6
|
-
fields,
|
|
7
|
-
isClientSide
|
|
8
|
-
}: {
|
|
4
|
+
declare function toZodSchema<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean>({ fields, isClientSide }: {
|
|
9
5
|
fields: Fields;
|
|
10
6
|
/**
|
|
11
7
|
* If true, then any fields that have `input: false` will be removed from the schema to prevent user input.
|
|
12
8
|
*/
|
|
13
9
|
isClientSide: IsClientSide;
|
|
14
|
-
}): z.ZodObject<RemoveNeverProps<{ [key in keyof Fields]: FieldAttributeToSchema<Fields[key], IsClientSide
|
|
10
|
+
}): z.ZodObject<RemoveNeverProps<{ [key in keyof Fields]: FieldAttributeToSchema<Fields[key], IsClientSide>; }>, z.core.$strip>;
|
|
15
11
|
type FieldAttributeToSchema<Field extends DBFieldAttribute | Record<string, never>, isClientSide extends boolean = false> = Field extends {
|
|
16
12
|
type: any;
|
|
17
13
|
} ? GetInput<isClientSide, Field, GetRequired<Field, GetType<Field>>> : Record<string, never>;
|
|
@@ -30,6 +26,6 @@ type GetRequired<F extends DBFieldAttribute, Schema extends z.core.SomeType> = F
|
|
|
30
26
|
type GetInput<isClientSide extends boolean, Field extends DBFieldAttribute, Schema extends z.core.SomeType> = Field extends {
|
|
31
27
|
input: false;
|
|
32
28
|
} ? isClientSide extends true ? never : Schema : Schema;
|
|
33
|
-
type RemoveNeverProps<T> = { [K in keyof T as [T[K]] extends [never] ? never : K]: T[K] };
|
|
29
|
+
type RemoveNeverProps<T> = { [K in keyof T as [T[K]] extends [never] ? never : K]: T[K]; };
|
|
34
30
|
//#endregion
|
|
35
31
|
export { FieldAttributeToSchema, toZodSchema };
|
package/dist/db/with-hooks.d.mts
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,7 @@ import { generateState, parseState } from "./oauth2/state.mjs";
|
|
|
11
11
|
import { StateData, generateGenericState, parseGenericState } from "./state.mjs";
|
|
12
12
|
import { HIDE_METADATA } from "./utils/hide-metadata.mjs";
|
|
13
13
|
import { getBaseURL, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes } from "./utils/url.mjs";
|
|
14
|
+
import "./utils/index.mjs";
|
|
14
15
|
import { APIError } from "./api/index.mjs";
|
|
15
16
|
import { StandardSchemaV1 } from "@better-auth/core";
|
|
16
17
|
import { getCurrentAdapter } from "@better-auth/core/context";
|
|
@@ -25,6 +26,6 @@ export * from "@better-auth/core/utils/error-codes";
|
|
|
25
26
|
export * from "@better-auth/core/utils/id";
|
|
26
27
|
export * from "@better-auth/core/utils/json";
|
|
27
28
|
export * from "@better-auth/core/social-providers";
|
|
28
|
-
export * from "better-call";
|
|
29
|
-
export * from "zod";
|
|
30
|
-
export { APIError, Account, AdditionalSessionFieldsInput, AdditionalUserFieldsInput, Auth, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientStore, DBAdapter, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, ExtractPluginField, FilteredAPI, HIDE_METADATA, HasRequiredKeys, InferAPI, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPluginFieldFromTuple, InferPluginIDs, InferPluginTypes, InferSessionAPI, InferSessionFromClient, InferUserFromClient, IsAny, IsSignal, type JSONWebKeySet, type JWTPayload, JoinConfig, JoinOption, OverrideMerge, Prettify, PrettifyDeep, RateLimit, RequiredKeysOf, Session, SessionQueryParams, type StandardSchemaV1, StateData, StoreIdentifierOption, StripEmptyObjects, type TelemetryEvent, UnionToIntersection, User, Verification, Where, betterAuth, createTelemetry, generateGenericState, generateState, getBaseURL, getCurrentAdapter, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, getTelemetryAuthConfig, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, parseGenericState, parseState, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes };
|
|
29
|
+
export type * from "better-call";
|
|
30
|
+
export type * from "zod";
|
|
31
|
+
export { APIError, type Account, type AdditionalSessionFieldsInput, type AdditionalUserFieldsInput, type Auth, type BetterAuthAdvancedOptions, type BetterAuthClientOptions, type BetterAuthClientPlugin, type BetterAuthCookies, type BetterAuthOptions, type BetterAuthPlugin, type BetterAuthRateLimitOptions, type ClientAtomListener, type ClientStore, type DBAdapter, type DBAdapterInstance, type DBAdapterSchemaCreation, type DBTransactionAdapter, type ExtractPluginField, FilteredAPI, HIDE_METADATA, type HasRequiredKeys, InferAPI, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, type InferOptionSchema, type InferPluginContext, type InferPluginErrorCodes, type InferPluginFieldFromTuple, type InferPluginIDs, type InferPluginTypes, InferSessionAPI, InferSessionFromClient, InferUserFromClient, type IsAny, IsSignal, type JSONWebKeySet, type JWTPayload, type JoinConfig, type JoinOption, type OverrideMerge, type Prettify, type PrettifyDeep, type RateLimit, type RequiredKeysOf, type Session, SessionQueryParams, type StandardSchemaV1, type StateData, type StoreIdentifierOption, type StripEmptyObjects, type TelemetryEvent, type UnionToIntersection, type User, type Verification, type Where, betterAuth, createTelemetry, generateGenericState, generateState, getBaseURL, getCurrentAdapter, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, getTelemetryAuthConfig, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, parseGenericState, parseState, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as _better_auth_core0 from "@better-auth/core";
|
|
2
|
-
import * as better_call0 from "better-call";
|
|
3
|
-
|
|
4
1
|
//#region src/integrations/next-js.d.ts
|
|
5
2
|
declare function toNextJsHandler(auth: {
|
|
6
3
|
handler: (request: Request) => Promise<Response>;
|
|
@@ -16,12 +13,12 @@ declare const nextCookies: () => {
|
|
|
16
13
|
version: string;
|
|
17
14
|
hooks: {
|
|
18
15
|
before: {
|
|
19
|
-
matcher(ctx:
|
|
20
|
-
handler: (inputContext:
|
|
16
|
+
matcher(ctx: import("@better-auth/core").HookEndpointContext): boolean;
|
|
17
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
21
18
|
}[];
|
|
22
19
|
after: {
|
|
23
|
-
matcher(ctx:
|
|
24
|
-
handler: (inputContext:
|
|
20
|
+
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
21
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
25
22
|
}[];
|
|
26
23
|
};
|
|
27
24
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Auth } from "../types/auth.mjs";
|
|
2
|
-
import
|
|
2
|
+
import "../types/index.mjs";
|
|
3
3
|
import { IncomingHttpHeaders } from "node:http";
|
|
4
|
-
|
|
5
4
|
//#region src/integrations/node.d.ts
|
|
6
5
|
declare const toNodeHandler: (auth: {
|
|
7
6
|
handler: Auth["handler"];
|
|
8
|
-
} | Auth["handler"]) => (req:
|
|
7
|
+
} | Auth["handler"]) => (req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse) => Promise<void>;
|
|
9
8
|
declare function fromNodeHeaders(nodeHeaders: IncomingHttpHeaders): Headers;
|
|
10
9
|
//#endregion
|
|
11
10
|
export { fromNodeHeaders, toNodeHandler };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { BetterAuthOptions } from "../types/index.mjs";
|
|
2
|
-
import * as better_call0 from "better-call";
|
|
3
2
|
import { RequestEvent } from "@sveltejs/kit";
|
|
4
|
-
|
|
5
3
|
//#region src/integrations/svelte-kit.d.ts
|
|
6
4
|
declare const toSvelteKitHandler: (auth: {
|
|
7
5
|
handler: (request: Request) => Response | Promise<Response>;
|
|
@@ -9,12 +7,7 @@ declare const toSvelteKitHandler: (auth: {
|
|
|
9
7
|
}) => (event: {
|
|
10
8
|
request: Request;
|
|
11
9
|
}) => Response | Promise<Response>;
|
|
12
|
-
declare const svelteKitHandler: ({
|
|
13
|
-
auth,
|
|
14
|
-
event,
|
|
15
|
-
resolve,
|
|
16
|
-
building
|
|
17
|
-
}: {
|
|
10
|
+
declare const svelteKitHandler: ({ auth, event, resolve, building }: {
|
|
18
11
|
auth: {
|
|
19
12
|
handler: (request: Request) => Response | Promise<Response>;
|
|
20
13
|
options: BetterAuthOptions;
|
|
@@ -30,7 +23,7 @@ declare const sveltekitCookies: (getRequestEvent: () => RequestEvent<any, any>)
|
|
|
30
23
|
hooks: {
|
|
31
24
|
after: {
|
|
32
25
|
matcher(): true;
|
|
33
|
-
handler: (inputContext:
|
|
26
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
34
27
|
}[];
|
|
35
28
|
};
|
|
36
29
|
};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as _better_auth_core0 from "@better-auth/core";
|
|
2
|
-
import * as better_call0 from "better-call";
|
|
3
|
-
|
|
4
1
|
//#region src/integrations/tanstack-start-solid.d.ts
|
|
5
2
|
/**
|
|
6
3
|
* TanStack Start cookie plugin for Solid.js.
|
|
@@ -24,8 +21,8 @@ declare const tanstackStartCookies: () => {
|
|
|
24
21
|
version: string;
|
|
25
22
|
hooks: {
|
|
26
23
|
after: {
|
|
27
|
-
matcher(ctx:
|
|
28
|
-
handler: (inputContext:
|
|
24
|
+
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
25
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
29
26
|
}[];
|
|
30
27
|
};
|
|
31
28
|
};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as _better_auth_core0 from "@better-auth/core";
|
|
2
|
-
import * as better_call0 from "better-call";
|
|
3
|
-
|
|
4
1
|
//#region src/integrations/tanstack-start.d.ts
|
|
5
2
|
/**
|
|
6
3
|
* TanStack Start cookie plugin for React.
|
|
@@ -24,8 +21,8 @@ declare const tanstackStartCookies: () => {
|
|
|
24
21
|
version: string;
|
|
25
22
|
hooks: {
|
|
26
23
|
after: {
|
|
27
|
-
matcher(ctx:
|
|
28
|
-
handler: (inputContext:
|
|
24
|
+
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
25
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
29
26
|
}[];
|
|
30
27
|
};
|
|
31
28
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Account, User } from "../types/models.mjs";
|
|
2
|
+
import "../types/index.mjs";
|
|
2
3
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
|
|
4
4
|
//#region src/oauth2/link-account.d.ts
|
|
5
5
|
declare function handleOAuthUserInfo(c: GenericEndpointContext, opts: {
|
|
6
6
|
userInfo: Omit<User, "createdAt" | "updatedAt">;
|
package/dist/oauth2/state.d.mts
CHANGED
package/dist/oauth2/utils.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AuthContext } from "@better-auth/core";
|
|
2
|
-
|
|
3
2
|
//#region src/oauth2/utils.d.ts
|
|
4
3
|
declare function decryptOAuthToken(token: string, ctx: AuthContext): string | Promise<string>;
|
|
5
4
|
declare function setTokenUtil(token: string | null | undefined, ctx: AuthContext): string | Promise<string> | null | undefined;
|
package/dist/package.mjs
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { AuthorizeResponse, createAccessControl } from "./access.mjs";
|
|
2
2
|
import { LiteralString } from "@better-auth/core";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/access/types.d.ts
|
|
5
4
|
type ArrayElement<T> = T extends readonly (infer E)[] ? E : never;
|
|
6
5
|
type SubArray<T extends unknown[] | readonly unknown[] | any[]> = T[number][] | ReadonlyArray<T[number]>;
|
|
7
|
-
type Subset<K extends keyof R, R extends Record<string | LiteralString, readonly string[] | readonly LiteralString[]>> = { [P in K]: SubArray<R[P]
|
|
6
|
+
type Subset<K extends keyof R, R extends Record<string | LiteralString, readonly string[] | readonly LiteralString[]>> = { [P in K]: SubArray<R[P]>; };
|
|
8
7
|
type Statements = {
|
|
9
8
|
readonly [resource: string]: readonly LiteralString[];
|
|
10
9
|
};
|
|
11
|
-
type RoleStatements<TStatements extends Statements> = { readonly [P in keyof TStatements]?: SubArray<TStatements[P]
|
|
10
|
+
type RoleStatements<TStatements extends Statements> = { readonly [P in keyof TStatements]?: SubArray<TStatements[P]>; };
|
|
12
11
|
type RoleInput<TStatements extends Statements, TRoleStatements extends Statements> = TRoleStatements & (string extends keyof TRoleStatements ? {} : RoleStatements<TStatements> & Record<Exclude<keyof TRoleStatements, keyof TStatements>, never>);
|
|
13
|
-
type ExactRoleStatements<TStatements extends Statements> = { readonly [P in keyof TStatements]: readonly [...TStatements[P]] };
|
|
12
|
+
type ExactRoleStatements<TStatements extends Statements> = { readonly [P in keyof TStatements]: readonly [...TStatements[P]]; };
|
|
14
13
|
type AccessControl<TStatements extends Statements = Statements> = ReturnType<typeof createAccessControl<TStatements>>;
|
|
15
14
|
type RoleAuthorizeRequest<TStatements extends Statements> = { [P in keyof TStatements]?: SubArray<TStatements[P]> | {
|
|
16
15
|
actions: SubArray<TStatements[P]>;
|
|
17
16
|
connector: "OR" | "AND";
|
|
18
|
-
} };
|
|
17
|
+
}; };
|
|
19
18
|
type Role<TRoleStatements extends Statements = Record<string, any>, TAuthorizeStatements extends Statements = TRoleStatements> = {
|
|
20
19
|
authorize: (request: RoleAuthorizeRequest<TAuthorizeStatements>, connector?: ("OR" | "AND") | undefined) => AuthorizeResponse;
|
|
21
20
|
statements: TRoleStatements;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ExactRoleStatements, Role, RoleInput, Statements } from "../../access/types.mjs";
|
|
2
|
+
import "../../index.mjs";
|
|
2
3
|
//#region src/plugins/admin/access/statement.d.ts
|
|
3
4
|
declare const defaultStatements: {
|
|
4
5
|
readonly user: readonly ["create", "list", "set-role", "ban", "impersonate", "impersonate-admins", "delete", "set-password", "set-email", "get", "update"];
|