@masheev/better-auth 0.0.0-stage → 1.7.5
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/LICENSE.md +20 -0
- package/README.md +31 -2
- package/TYPE-PATCH-NOTICE.md +9 -0
- package/TYPE-PATCH-PROVENANCE.json +267 -0
- package/dist/_virtual/_rolldown/runtime.mjs +27 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +1 -0
- package/dist/adapters/drizzle-adapter/index.mjs +2 -0
- package/dist/adapters/index.d.mts +26 -0
- package/dist/adapters/index.mjs +9 -0
- package/dist/adapters/kysely-adapter/index.d.mts +1 -0
- package/dist/adapters/kysely-adapter/index.mjs +2 -0
- package/dist/adapters/memory-adapter/index.d.mts +1 -0
- package/dist/adapters/memory-adapter/index.mjs +2 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +1 -0
- package/dist/adapters/mongodb-adapter/index.mjs +2 -0
- package/dist/adapters/prisma-adapter/index.d.mts +1 -0
- package/dist/adapters/prisma-adapter/index.mjs +2 -0
- package/dist/api/dispatch.d.mts +34 -0
- package/dist/api/dispatch.mjs +275 -0
- package/dist/api/index.d.mts +4053 -0
- package/dist/api/index.mjs +220 -0
- package/dist/api/middlewares/authorization.d.mts +69 -0
- package/dist/api/middlewares/authorization.mjs +78 -0
- package/dist/api/middlewares/index.d.mts +2 -0
- package/dist/api/middlewares/origin-check.d.mts +17 -0
- package/dist/api/middlewares/origin-check.mjs +155 -0
- package/dist/api/rate-limiter/index.mjs +318 -0
- package/dist/api/routes/account.d.mts +413 -0
- package/dist/api/routes/account.mjs +619 -0
- package/dist/api/routes/callback.d.mts +32 -0
- package/dist/api/routes/callback.mjs +261 -0
- package/dist/api/routes/email-verification.d.mts +160 -0
- package/dist/api/routes/email-verification.mjs +324 -0
- package/dist/api/routes/error.d.mts +27 -0
- package/dist/api/routes/error.mjs +387 -0
- package/dist/api/routes/index.d.mts +12 -0
- package/dist/api/routes/ok.d.mts +35 -0
- package/dist/api/routes/ok.mjs +27 -0
- package/dist/api/routes/password.d.mts +182 -0
- package/dist/api/routes/password.mjs +206 -0
- package/dist/api/routes/session.d.mts +450 -0
- package/dist/api/routes/session.mjs +481 -0
- package/dist/api/routes/sign-in.d.mts +186 -0
- package/dist/api/routes/sign-in.mjs +368 -0
- package/dist/api/routes/sign-out.d.mts +51 -0
- package/dist/api/routes/sign-out.mjs +96 -0
- package/dist/api/routes/sign-up.d.mts +159 -0
- package/dist/api/routes/sign-up.mjs +275 -0
- package/dist/api/routes/update-session.d.mts +74 -0
- package/dist/api/routes/update-session.mjs +57 -0
- package/dist/api/routes/update-user.d.mts +428 -0
- package/dist/api/routes/update-user.mjs +522 -0
- package/dist/api/state/oauth.d.mts +53 -0
- package/dist/api/state/oauth.mjs +38 -0
- package/dist/api/state/should-session-refresh.d.mts +12 -0
- package/dist/api/state/should-session-refresh.mjs +13 -0
- package/dist/api/to-auth-endpoints.mjs +60 -0
- package/dist/auth/base.mjs +66 -0
- package/dist/auth/full.d.mts +28 -0
- package/dist/auth/full.mjs +29 -0
- package/dist/auth/minimal.d.mts +10 -0
- package/dist/auth/minimal.mjs +11 -0
- package/dist/auth/trusted-origins.mjs +106 -0
- package/dist/client/broadcast-channel.d.mts +19 -0
- package/dist/client/broadcast-channel.mjs +44 -0
- package/dist/client/config.d.mts +90 -0
- package/dist/client/config.mjs +113 -0
- package/dist/client/equality.d.mts +19 -0
- package/dist/client/equality.mjs +42 -0
- package/dist/client/fetch-plugins.mjs +17 -0
- package/dist/client/focus-manager.d.mts +10 -0
- package/dist/client/focus-manager.mjs +30 -0
- package/dist/client/index.d.mts +35 -0
- package/dist/client/index.mjs +22 -0
- package/dist/client/lynx/index.d.mts +43 -0
- package/dist/client/lynx/index.mjs +22 -0
- package/dist/client/lynx/lynx-store.d.mts +46 -0
- package/dist/client/lynx/lynx-store.mjs +44 -0
- package/dist/client/online-manager.d.mts +11 -0
- package/dist/client/online-manager.mjs +33 -0
- package/dist/client/parser.d.mts +10 -0
- package/dist/client/parser.mjs +70 -0
- package/dist/client/path-to-object.d.mts +113 -0
- package/dist/client/plugins/index.d.mts +44 -0
- package/dist/client/plugins/index.mjs +30 -0
- package/dist/client/plugins/infer-plugin.d.mts +16 -0
- package/dist/client/plugins/infer-plugin.mjs +11 -0
- package/dist/client/proxy.mjs +78 -0
- package/dist/client/query.d.mts +23 -0
- package/dist/client/query.mjs +124 -0
- package/dist/client/react/index.d.mts +44 -0
- package/dist/client/react/index.mjs +22 -0
- package/dist/client/react/react-store.d.mts +46 -0
- package/dist/client/react/react-store.mjs +44 -0
- package/dist/client/session-atom.d.mts +11 -0
- package/dist/client/session-atom.mjs +178 -0
- package/dist/client/session-refresh.d.mts +20 -0
- package/dist/client/session-refresh.mjs +131 -0
- package/dist/client/solid/index.d.mts +44 -0
- package/dist/client/solid/index.mjs +22 -0
- package/dist/client/solid/solid-store.mjs +21 -0
- package/dist/client/svelte/index.d.mts +44 -0
- package/dist/client/svelte/index.mjs +18 -0
- package/dist/client/types.d.mts +51 -0
- package/dist/client/vanilla.d.mts +42 -0
- package/dist/client/vanilla.mjs +18 -0
- package/dist/client/vue/index.d.mts +67 -0
- package/dist/client/vue/index.mjs +54 -0
- package/dist/client/vue/vue-store.mjs +23 -0
- package/dist/context/create-context.mjs +235 -0
- package/dist/context/helpers.mjs +158 -0
- package/dist/context/init-minimal.mjs +17 -0
- package/dist/context/init.mjs +19 -0
- package/dist/context/secret-utils.mjs +53 -0
- package/dist/context/store-capabilities.mjs +12 -0
- package/dist/cookies/cache.mjs +33 -0
- package/dist/cookies/cookie-utils.d.mts +72 -0
- package/dist/cookies/cookie-utils.mjs +203 -0
- package/dist/cookies/index.d.mts +124 -0
- package/dist/cookies/index.mjs +350 -0
- package/dist/cookies/jwt.mjs +44 -0
- package/dist/cookies/session-store.d.mts +32 -0
- package/dist/cookies/session-store.mjs +183 -0
- package/dist/crypto/buffer.d.mts +7 -0
- package/dist/crypto/buffer.mjs +16 -0
- package/dist/crypto/index.d.mts +32 -0
- package/dist/crypto/index.mjs +69 -0
- package/dist/crypto/jwt.d.mts +9 -0
- package/dist/crypto/jwt.mjs +141 -0
- package/dist/crypto/password.d.mts +13 -0
- package/dist/crypto/password.mjs +14 -0
- package/dist/crypto/random.d.mts +4 -0
- package/dist/crypto/random.mjs +5 -0
- package/dist/db/adapter-base.d.mts +7 -0
- package/dist/db/adapter-base.mjs +25 -0
- package/dist/db/adapter-kysely.d.mts +7 -0
- package/dist/db/adapter-kysely.mjs +17 -0
- package/dist/db/field-converter.d.mts +7 -0
- package/dist/db/field-converter.mjs +19 -0
- package/dist/db/field.d.mts +41 -0
- package/dist/db/get-migration.d.mts +56 -0
- package/dist/db/get-migration.mjs +685 -0
- package/dist/db/get-schema.d.mts +13 -0
- package/dist/db/get-schema.mjs +39 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +35 -0
- package/dist/db/internal-adapter.d.mts +14 -0
- package/dist/db/internal-adapter.mjs +951 -0
- package/dist/db/revoke-unproven-account-access.d.mts +21 -0
- package/dist/db/revoke-unproven-account-access.mjs +58 -0
- package/dist/db/schema.d.mts +62 -0
- package/dist/db/schema.mjs +161 -0
- package/dist/db/to-zod.d.mts +35 -0
- package/dist/db/to-zod.mjs +23 -0
- package/dist/db/verification-token-storage.mjs +25 -0
- package/dist/db/with-hooks.d.mts +37 -0
- package/dist/db/with-hooks.mjs +255 -0
- package/dist/index.d.mts +30 -0
- package/dist/index.mjs +17 -0
- package/dist/integrations/cookie-plugin-guard.mjs +18 -0
- package/dist/integrations/next-js.d.mts +29 -0
- package/dist/integrations/next-js.mjs +105 -0
- package/dist/integrations/node.d.mts +11 -0
- package/dist/integrations/node.mjs +13 -0
- package/dist/integrations/solid-start.d.mts +22 -0
- package/dist/integrations/solid-start.mjs +15 -0
- package/dist/integrations/svelte-kit.d.mts +38 -0
- package/dist/integrations/svelte-kit.mjs +57 -0
- package/dist/integrations/tanstack-start-solid.d.mts +33 -0
- package/dist/integrations/tanstack-start-solid.mjs +57 -0
- package/dist/integrations/tanstack-start.d.mts +33 -0
- package/dist/integrations/tanstack-start.mjs +57 -0
- package/dist/oauth2/account-key.mjs +43 -0
- package/dist/oauth2/errors.mjs +49 -0
- package/dist/oauth2/index.d.mts +5 -0
- package/dist/oauth2/index.mjs +5 -0
- package/dist/oauth2/link-account.d.mts +96 -0
- package/dist/oauth2/link-account.mjs +329 -0
- package/dist/oauth2/state.d.mts +54 -0
- package/dist/oauth2/state.mjs +67 -0
- package/dist/oauth2/utils.d.mts +11 -0
- package/dist/oauth2/utils.mjs +33 -0
- package/dist/package.mjs +4 -0
- package/dist/plugins/access/access.d.mts +17 -0
- package/dist/plugins/access/access.mjs +78 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +2 -0
- package/dist/plugins/access/types.d.mts +24 -0
- package/dist/plugins/additional-fields/client.d.mts +100 -0
- package/dist/plugins/additional-fields/client.mjs +11 -0
- package/dist/plugins/admin/access/index.d.mts +2 -0
- package/dist/plugins/admin/access/index.mjs +2 -0
- package/dist/plugins/admin/access/statement.d.mts +51 -0
- package/dist/plugins/admin/access/statement.mjs +52 -0
- package/dist/plugins/admin/admin.d.mts +911 -0
- package/dist/plugins/admin/admin.mjs +89 -0
- package/dist/plugins/admin/client.d.mts +81 -0
- package/dist/plugins/admin/client.mjs +39 -0
- package/dist/plugins/admin/error-codes.d.mts +30 -0
- package/dist/plugins/admin/error-codes.mjs +29 -0
- package/dist/plugins/admin/has-permission.mjs +12 -0
- package/dist/plugins/admin/index.d.mts +3 -0
- package/dist/plugins/admin/index.mjs +2 -0
- package/dist/plugins/admin/routes.mjs +919 -0
- package/dist/plugins/admin/schema.d.mts +40 -0
- package/dist/plugins/admin/schema.mjs +33 -0
- package/dist/plugins/admin/types.d.mts +88 -0
- package/dist/plugins/anonymous/client.d.mts +32 -0
- package/dist/plugins/anonymous/client.mjs +21 -0
- package/dist/plugins/anonymous/error-codes.d.mts +15 -0
- package/dist/plugins/anonymous/error-codes.mjs +14 -0
- package/dist/plugins/anonymous/index.d.mts +175 -0
- package/dist/plugins/anonymous/index.mjs +219 -0
- package/dist/plugins/anonymous/schema.d.mts +15 -0
- package/dist/plugins/anonymous/schema.mjs +9 -0
- package/dist/plugins/anonymous/types.d.mts +65 -0
- package/dist/plugins/bearer/index.d.mts +45 -0
- package/dist/plugins/bearer/index.mjs +74 -0
- package/dist/plugins/captcha/constants.d.mts +9 -0
- package/dist/plugins/captcha/constants.mjs +27 -0
- package/dist/plugins/captcha/error-codes.mjs +13 -0
- package/dist/plugins/captcha/index.d.mts +27 -0
- package/dist/plugins/captcha/index.mjs +79 -0
- package/dist/plugins/captcha/types.d.mts +52 -0
- package/dist/plugins/captcha/utils.mjs +9 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs +27 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +47 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +32 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +27 -0
- package/dist/plugins/custom-session/client.d.mts +17 -0
- package/dist/plugins/custom-session/client.mjs +7 -0
- package/dist/plugins/custom-session/index.d.mts +73 -0
- package/dist/plugins/custom-session/index.mjs +65 -0
- package/dist/plugins/device-authorization/client.d.mts +17 -0
- package/dist/plugins/device-authorization/client.mjs +18 -0
- package/dist/plugins/device-authorization/error-codes.mjs +19 -0
- package/dist/plugins/device-authorization/index.d.mts +558 -0
- package/dist/plugins/device-authorization/index.mjs +87 -0
- package/dist/plugins/device-authorization/routes.d.mts +32 -0
- package/dist/plugins/device-authorization/routes.mjs +725 -0
- package/dist/plugins/device-authorization/schema.d.mts +18 -0
- package/dist/plugins/device-authorization/schema.mjs +63 -0
- package/dist/plugins/email-otp/client.d.mts +21 -0
- package/dist/plugins/email-otp/client.mjs +17 -0
- package/dist/plugins/email-otp/error-codes.d.mts +10 -0
- package/dist/plugins/email-otp/error-codes.mjs +9 -0
- package/dist/plugins/email-otp/index.d.mts +551 -0
- package/dist/plugins/email-otp/index.mjs +145 -0
- package/dist/plugins/email-otp/otp-token.mjs +55 -0
- package/dist/plugins/email-otp/routes.mjs +784 -0
- package/dist/plugins/email-otp/types.d.mts +109 -0
- package/dist/plugins/email-otp/utils.mjs +17 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +8 -0
- package/dist/plugins/generic-oauth/index.d.mts +52 -0
- package/dist/plugins/generic-oauth/index.mjs +279 -0
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +36 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs +49 -0
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +31 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +36 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/index.d.mts +10 -0
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +36 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs +47 -0
- package/dist/plugins/generic-oauth/providers/line.d.mts +54 -0
- package/dist/plugins/generic-oauth/providers/line.mjs +93 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +39 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +104 -0
- package/dist/plugins/generic-oauth/providers/okta.d.mts +36 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs +47 -0
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +29 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs +61 -0
- package/dist/plugins/generic-oauth/providers/slack.d.mts +29 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs +63 -0
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +29 -0
- package/dist/plugins/generic-oauth/providers/yandex.mjs +67 -0
- package/dist/plugins/generic-oauth/types.d.mts +268 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +63 -0
- package/dist/plugins/haveibeenpwned/index.mjs +81 -0
- package/dist/plugins/index.d.mts +69 -0
- package/dist/plugins/index.mjs +49 -0
- package/dist/plugins/jwt/adapter.mjs +68 -0
- package/dist/plugins/jwt/client.d.mts +41 -0
- package/dist/plugins/jwt/client.mjs +19 -0
- package/dist/plugins/jwt/cookie-cache.mjs +77 -0
- package/dist/plugins/jwt/index.d.mts +246 -0
- package/dist/plugins/jwt/index.mjs +214 -0
- package/dist/plugins/jwt/schema.d.mts +33 -0
- package/dist/plugins/jwt/schema.mjs +29 -0
- package/dist/plugins/jwt/sign.d.mts +128 -0
- package/dist/plugins/jwt/sign.mjs +130 -0
- package/dist/plugins/jwt/types.d.mts +256 -0
- package/dist/plugins/jwt/utils.d.mts +41 -0
- package/dist/plugins/jwt/utils.mjs +64 -0
- package/dist/plugins/jwt/verify.d.mts +11 -0
- package/dist/plugins/jwt/verify.mjs +45 -0
- package/dist/plugins/last-login-method/client.d.mts +48 -0
- package/dist/plugins/last-login-method/client.mjs +48 -0
- package/dist/plugins/last-login-method/index.d.mts +127 -0
- package/dist/plugins/last-login-method/index.mjs +98 -0
- package/dist/plugins/magic-link/client.d.mts +10 -0
- package/dist/plugins/magic-link/client.mjs +11 -0
- package/dist/plugins/magic-link/index.d.mts +213 -0
- package/dist/plugins/magic-link/index.mjs +208 -0
- package/dist/plugins/magic-link/utils.mjs +9 -0
- package/dist/plugins/multi-session/client.d.mts +19 -0
- package/dist/plugins/multi-session/client.mjs +19 -0
- package/dist/plugins/multi-session/error-codes.d.mts +8 -0
- package/dist/plugins/multi-session/error-codes.mjs +5 -0
- package/dist/plugins/multi-session/index.d.mts +212 -0
- package/dist/plugins/multi-session/index.mjs +217 -0
- package/dist/plugins/oauth-popup/client.d.mts +82 -0
- package/dist/plugins/oauth-popup/client.mjs +203 -0
- package/dist/plugins/oauth-popup/constants.d.mts +11 -0
- package/dist/plugins/oauth-popup/constants.mjs +11 -0
- package/dist/plugins/oauth-popup/error-codes.d.mts +11 -0
- package/dist/plugins/oauth-popup/error-codes.mjs +10 -0
- package/dist/plugins/oauth-popup/index.d.mts +67 -0
- package/dist/plugins/oauth-popup/index.mjs +232 -0
- package/dist/plugins/oauth-popup/types.d.mts +30 -0
- package/dist/plugins/oauth-proxy/index.d.mts +130 -0
- package/dist/plugins/oauth-proxy/index.mjs +407 -0
- package/dist/plugins/oauth-proxy/utils.mjs +55 -0
- package/dist/plugins/one-tap/client.d.mts +174 -0
- package/dist/plugins/one-tap/client.mjs +208 -0
- package/dist/plugins/one-tap/index.d.mts +82 -0
- package/dist/plugins/one-tap/index.mjs +100 -0
- package/dist/plugins/one-time-token/client.d.mts +10 -0
- package/dist/plugins/one-time-token/client.mjs +11 -0
- package/dist/plugins/one-time-token/index.d.mts +132 -0
- package/dist/plugins/one-time-token/index.mjs +107 -0
- package/dist/plugins/one-time-token/utils.mjs +9 -0
- package/dist/plugins/open-api/generator.d.mts +126 -0
- package/dist/plugins/open-api/generator.mjs +557 -0
- package/dist/plugins/open-api/index.d.mts +97 -0
- package/dist/plugins/open-api/index.mjs +65 -0
- package/dist/plugins/open-api/logo.mjs +13 -0
- package/dist/plugins/organization/access/index.d.mts +2 -0
- package/dist/plugins/organization/access/index.mjs +2 -0
- package/dist/plugins/organization/access/statement.d.mts +113 -0
- package/dist/plugins/organization/access/statement.mjs +77 -0
- package/dist/plugins/organization/adapter.d.mts +815 -0
- package/dist/plugins/organization/adapter.mjs +813 -0
- package/dist/plugins/organization/call.mjs +15 -0
- package/dist/plugins/organization/client.d.mts +375 -0
- package/dist/plugins/organization/client.mjs +104 -0
- package/dist/plugins/organization/error-codes.d.mts +66 -0
- package/dist/plugins/organization/error-codes.mjs +65 -0
- package/dist/plugins/organization/has-permission.d.mts +17 -0
- package/dist/plugins/organization/has-permission.mjs +34 -0
- package/dist/plugins/organization/index.d.mts +6 -0
- package/dist/plugins/organization/index.mjs +4 -0
- package/dist/plugins/organization/organization.d.mts +420 -0
- package/dist/plugins/organization/organization.mjs +886 -0
- package/dist/plugins/organization/permission.d.mts +15 -0
- package/dist/plugins/organization/permission.mjs +14 -0
- package/dist/plugins/organization/routes/crud-access-control.d.mts +511 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +674 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +1154 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +602 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +1057 -0
- package/dist/plugins/organization/routes/crud-members.mjs +518 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +918 -0
- package/dist/plugins/organization/routes/crud-org.mjs +455 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +1238 -0
- package/dist/plugins/organization/routes/crud-team.mjs +766 -0
- package/dist/plugins/organization/schema.d.mts +390 -0
- package/dist/plugins/organization/schema.mjs +65 -0
- package/dist/plugins/organization/types.d.mts +691 -0
- package/dist/plugins/phone-number/client.d.mts +31 -0
- package/dist/plugins/phone-number/client.mjs +19 -0
- package/dist/plugins/phone-number/error-codes.d.mts +19 -0
- package/dist/plugins/phone-number/error-codes.mjs +18 -0
- package/dist/plugins/phone-number/index.d.mts +360 -0
- package/dist/plugins/phone-number/index.mjs +57 -0
- package/dist/plugins/phone-number/routes.mjs +529 -0
- package/dist/plugins/phone-number/schema.d.mts +22 -0
- package/dist/plugins/phone-number/schema.mjs +18 -0
- package/dist/plugins/phone-number/types.d.mts +116 -0
- package/dist/plugins/siwe/client.d.mts +14 -0
- package/dist/plugins/siwe/client.mjs +15 -0
- package/dist/plugins/siwe/index.d.mts +62 -0
- package/dist/plugins/siwe/index.mjs +272 -0
- package/dist/plugins/siwe/parse-message.mjs +60 -0
- package/dist/plugins/siwe/schema.d.mts +35 -0
- package/dist/plugins/siwe/schema.mjs +30 -0
- package/dist/plugins/siwe/types.d.mts +43 -0
- package/dist/plugins/test-utils/auth-helpers.mjs +33 -0
- package/dist/plugins/test-utils/cookie-builder.mjs +55 -0
- package/dist/plugins/test-utils/db-helpers.mjs +65 -0
- package/dist/plugins/test-utils/factories.mjs +38 -0
- package/dist/plugins/test-utils/index.d.mts +73 -0
- package/dist/plugins/test-utils/index.mjs +97 -0
- package/dist/plugins/test-utils/otp-sink.mjs +21 -0
- package/dist/plugins/test-utils/types.d.mts +51 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +291 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs +341 -0
- package/dist/plugins/two-factor/client.d.mts +76 -0
- package/dist/plugins/two-factor/client.mjs +41 -0
- package/dist/plugins/two-factor/constant.mjs +6 -0
- package/dist/plugins/two-factor/error-code.d.mts +20 -0
- package/dist/plugins/two-factor/error-code.mjs +19 -0
- package/dist/plugins/two-factor/index.d.mts +720 -0
- package/dist/plugins/two-factor/index.mjs +349 -0
- package/dist/plugins/two-factor/otp/index.d.mts +216 -0
- package/dist/plugins/two-factor/otp/index.mjs +252 -0
- package/dist/plugins/two-factor/schema.d.mts +59 -0
- package/dist/plugins/two-factor/schema.mjs +53 -0
- package/dist/plugins/two-factor/totp/index.d.mts +219 -0
- package/dist/plugins/two-factor/totp/index.mjs +230 -0
- package/dist/plugins/two-factor/types.d.mts +111 -0
- package/dist/plugins/two-factor/utils.mjs +9 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs +205 -0
- package/dist/plugins/username/client.d.mts +38 -0
- package/dist/plugins/username/client.mjs +17 -0
- package/dist/plugins/username/error-codes.d.mts +16 -0
- package/dist/plugins/username/error-codes.mjs +15 -0
- package/dist/plugins/username/index.d.mts +326 -0
- package/dist/plugins/username/index.mjs +312 -0
- package/dist/plugins/username/schema.d.mts +50 -0
- package/dist/plugins/username/schema.mjs +25 -0
- package/dist/social-providers/index.d.mts +1 -0
- package/dist/social-providers/index.mjs +2 -0
- package/dist/state.d.mts +48 -0
- package/dist/state.mjs +149 -0
- package/dist/test-utils/headers.d.mts +8 -0
- package/dist/test-utils/headers.mjs +17 -0
- package/dist/test-utils/http-test-instance.d.mts +413 -0
- package/dist/test-utils/http-test-instance.mjs +107 -0
- package/dist/test-utils/index.d.mts +4 -0
- package/dist/test-utils/index.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +56 -0
- package/dist/test-utils/test-instance.mjs +242 -0
- package/dist/types/adapter.d.mts +2 -0
- package/dist/types/api.d.mts +28 -0
- package/dist/types/auth.d.mts +32 -0
- package/dist/types/helper.d.mts +26 -0
- package/dist/types/index.d.mts +10 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +10 -0
- package/dist/types/plugins.d.mts +19 -0
- package/dist/utils/boolean.mjs +6 -0
- package/dist/utils/constants.mjs +4 -0
- package/dist/utils/date.mjs +6 -0
- package/dist/utils/hashing.mjs +18 -0
- package/dist/utils/hide-metadata.d.mts +6 -0
- package/dist/utils/hide-metadata.mjs +4 -0
- package/dist/utils/index.d.mts +4 -0
- package/dist/utils/is-api-error.d.mts +2 -0
- package/dist/utils/is-api-error.mjs +2 -0
- package/dist/utils/is-atom.mjs +6 -0
- package/dist/utils/is-promise.mjs +6 -0
- package/dist/utils/middleware-response.mjs +7 -0
- package/dist/utils/password.mjs +32 -0
- package/dist/utils/plugin-helper.mjs +14 -0
- package/dist/utils/request.mjs +23 -0
- package/dist/utils/shim.mjs +22 -0
- package/dist/utils/time.d.mts +48 -0
- package/dist/utils/time.mjs +98 -0
- package/dist/utils/url.d.mts +78 -0
- package/dist/utils/url.mjs +238 -0
- package/dist/utils/validate-user-info.mjs +44 -0
- package/dist/utils/wildcard.mjs +106 -0
- package/dist/version.mjs +5 -0
- package/package.json +595 -3
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { toNodeHandler } from "../integrations/node.mjs";
|
|
2
|
+
import { getTestInstance } from "./test-instance.mjs";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
//#region src/test-utils/http-test-instance.ts
|
|
5
|
+
const closeHttpServer = (server) => new Promise((resolve, reject) => {
|
|
6
|
+
server.close((error) => {
|
|
7
|
+
if (error) {
|
|
8
|
+
reject(error);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
resolve();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
const endUnhandledErrorResponse = (res, error) => {
|
|
15
|
+
if (res.writableEnded || res.destroyed) return;
|
|
16
|
+
if (res.headersSent) {
|
|
17
|
+
res.end();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
res.statusCode = 500;
|
|
21
|
+
res.end(error instanceof Error ? error.message : "Internal Server Error");
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Binds an HTTP listener to an OS-assigned port before the final request
|
|
25
|
+
* handler exists. This lets tests construct URL-sensitive applications only
|
|
26
|
+
* after the listener owns its port, then install the application handler.
|
|
27
|
+
*/
|
|
28
|
+
async function createHttpTestServer() {
|
|
29
|
+
let activeHandler = (_req, res) => {
|
|
30
|
+
res.statusCode = 503;
|
|
31
|
+
res.end("Test HTTP listener has no handler bound yet");
|
|
32
|
+
};
|
|
33
|
+
const nodeServer = createServer((req, res) => {
|
|
34
|
+
Promise.resolve(activeHandler(req, res)).catch((error) => {
|
|
35
|
+
endUnhandledErrorResponse(res, error);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
await new Promise((resolve, reject) => {
|
|
39
|
+
const onError = (error) => {
|
|
40
|
+
nodeServer.off("listening", onListening);
|
|
41
|
+
reject(error);
|
|
42
|
+
};
|
|
43
|
+
const onListening = () => {
|
|
44
|
+
nodeServer.off("error", onError);
|
|
45
|
+
resolve();
|
|
46
|
+
};
|
|
47
|
+
nodeServer.once("error", onError);
|
|
48
|
+
nodeServer.once("listening", onListening);
|
|
49
|
+
nodeServer.listen(0, "127.0.0.1");
|
|
50
|
+
});
|
|
51
|
+
const address = nodeServer.address();
|
|
52
|
+
if (!address || typeof address === "string") {
|
|
53
|
+
await closeHttpServer(nodeServer);
|
|
54
|
+
throw new Error("HTTP test listener did not report a bound port for the test listener");
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
url: `http://127.0.0.1:${address.port}`,
|
|
58
|
+
address,
|
|
59
|
+
server: nodeServer,
|
|
60
|
+
setRequestHandler(handler) {
|
|
61
|
+
activeHandler = handler;
|
|
62
|
+
},
|
|
63
|
+
close: () => closeHttpServer(nodeServer)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Like `getTestInstance`, but bound to an actual HTTP listener on an
|
|
68
|
+
* OS-assigned port (`port: 0`). The discovered URL is fed back into the auth
|
|
69
|
+
* instance so its `baseURL` matches the listener.
|
|
70
|
+
*
|
|
71
|
+
* This removes the race window that the temp-server-then-rebind pattern
|
|
72
|
+
* introduces. The listener is bound once, holds the port for its lifetime,
|
|
73
|
+
* and only swaps in the real request handler after the auth instance is
|
|
74
|
+
* fully constructed.
|
|
75
|
+
*
|
|
76
|
+
* The caller is responsible for calling `server.close()` in `afterAll`. Any
|
|
77
|
+
* `baseURL` passed in `options` is ignored — the URL must match the
|
|
78
|
+
* listener.
|
|
79
|
+
*/
|
|
80
|
+
async function getHttpTestInstance(options, config) {
|
|
81
|
+
const server = await createHttpTestServer();
|
|
82
|
+
const baseURL = server.url;
|
|
83
|
+
try {
|
|
84
|
+
const instance = await getTestInstance({
|
|
85
|
+
...options,
|
|
86
|
+
baseURL
|
|
87
|
+
}, {
|
|
88
|
+
clientOptions: config?.clientOptions,
|
|
89
|
+
disableTestUser: config?.disableTestUser,
|
|
90
|
+
testUser: config?.testUser,
|
|
91
|
+
testWith: config?.testWith,
|
|
92
|
+
transaction: config?.transaction
|
|
93
|
+
});
|
|
94
|
+
server.setRequestHandler(config?.handler ? config.handler(instance.auth) : toNodeHandler(instance.auth.handler));
|
|
95
|
+
return {
|
|
96
|
+
...instance,
|
|
97
|
+
server,
|
|
98
|
+
baseURL,
|
|
99
|
+
port: server.address.port
|
|
100
|
+
};
|
|
101
|
+
} catch (error) {
|
|
102
|
+
await server.close();
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { createHttpTestServer, getHttpTestInstance };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { convertSetCookieToCookie } from "./headers.mjs";
|
|
2
|
+
import { getTestInstance } from "./test-instance.mjs";
|
|
3
|
+
import { HttpTestInstanceConfig, HttpTestRequestHandler, HttpTestServer, createHttpTestServer, getHttpTestInstance } from "./http-test-instance.mjs";
|
|
4
|
+
export { type HttpTestInstanceConfig, type HttpTestRequestHandler, type HttpTestServer, convertSetCookieToCookie, createHttpTestServer, getHttpTestInstance, getTestInstance };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { convertSetCookieToCookie } from "./headers.mjs";
|
|
2
|
+
import { getTestInstance } from "./test-instance.mjs";
|
|
3
|
+
import { createHttpTestServer, getHttpTestInstance } from "./http-test-instance.mjs";
|
|
4
|
+
export { convertSetCookieToCookie, createHttpTestServer, getHttpTestInstance, getTestInstance };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Session, User } from "../types/models.mjs";
|
|
2
|
+
import { Auth } from "../types/auth.mjs";
|
|
3
|
+
import { AuthClient } from "../client/vanilla.mjs";
|
|
4
|
+
import { setCookieToHeader } from "../cookies/cookie-utils.mjs";
|
|
5
|
+
import { Awaitable, BetterAuthClientOptions, BetterAuthOptions } from "@better-auth/core";
|
|
6
|
+
import * as _$_better_auth_core_db_adapter0 from "@better-auth/core/db/adapter";
|
|
7
|
+
import { SuccessContext } from "@better-fetch/fetch";
|
|
8
|
+
|
|
9
|
+
//#region src/test-utils/test-instance.d.ts
|
|
10
|
+
declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends BetterAuthClientOptions>(options?: O | undefined, config?: {
|
|
11
|
+
clientOptions?: C;
|
|
12
|
+
port?: number;
|
|
13
|
+
disableTestUser?: boolean;
|
|
14
|
+
testUser?: Partial<User>;
|
|
15
|
+
testWith?: "sqlite" | "postgres" | "mongodb" | "mysql";
|
|
16
|
+
transaction?: boolean;
|
|
17
|
+
} | undefined): Promise<{
|
|
18
|
+
auth: Auth<O>;
|
|
19
|
+
client: AuthClient<(C extends undefined ? {} : C) & {
|
|
20
|
+
baseURL: string | undefined;
|
|
21
|
+
fetchOptions: {
|
|
22
|
+
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
testUser: {
|
|
26
|
+
id?: string | undefined;
|
|
27
|
+
createdAt?: Date | undefined;
|
|
28
|
+
updatedAt?: Date | undefined;
|
|
29
|
+
email: string;
|
|
30
|
+
emailVerified?: boolean | undefined;
|
|
31
|
+
name: string;
|
|
32
|
+
image?: string | null | undefined;
|
|
33
|
+
password: string;
|
|
34
|
+
};
|
|
35
|
+
signInWithTestUser: () => Promise<{
|
|
36
|
+
session: Session;
|
|
37
|
+
user: User;
|
|
38
|
+
headers: Headers;
|
|
39
|
+
setCookie: (name: string, value: string) => void;
|
|
40
|
+
runWithUser: (fn: (headers: Headers) => Promise<void>) => Promise<void>;
|
|
41
|
+
}>;
|
|
42
|
+
signInWithUser: (email: string, password: string) => Promise<{
|
|
43
|
+
res: {
|
|
44
|
+
user: User;
|
|
45
|
+
session: Session;
|
|
46
|
+
};
|
|
47
|
+
headers: Headers;
|
|
48
|
+
}>;
|
|
49
|
+
cookieSetter: typeof setCookieToHeader;
|
|
50
|
+
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
51
|
+
sessionSetter: (headers: Headers) => (context: SuccessContext) => void;
|
|
52
|
+
db: _$_better_auth_core_db_adapter0.DBAdapter<BetterAuthOptions>;
|
|
53
|
+
runWithUser: (email: string, password: string, fn: (headers: Headers) => Awaitable<void>) => Promise<void>;
|
|
54
|
+
}>;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { getTestInstance };
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { getAdapter } from "../db/adapter-kysely.mjs";
|
|
2
|
+
import { getMigrations } from "../db/get-migration.mjs";
|
|
3
|
+
import { getBaseURL, isDynamicBaseURLConfig } from "../utils/url.mjs";
|
|
4
|
+
import { parseSetCookieHeader, setCookieToHeader } from "../cookies/cookie-utils.mjs";
|
|
5
|
+
import { betterAuth } from "../auth/full.mjs";
|
|
6
|
+
import { createAuthClient } from "../client/vanilla.mjs";
|
|
7
|
+
import { bearer } from "../plugins/bearer/index.mjs";
|
|
8
|
+
import { sql } from "kysely";
|
|
9
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
11
|
+
import { afterAll } from "vitest";
|
|
12
|
+
//#region src/test-utils/test-instance.ts
|
|
13
|
+
const cleanupSet = /* @__PURE__ */ new Set();
|
|
14
|
+
const currentUserContextStorage = new AsyncLocalStorage();
|
|
15
|
+
afterAll(async () => {
|
|
16
|
+
for (const cleanup of cleanupSet) {
|
|
17
|
+
await cleanup();
|
|
18
|
+
cleanupSet.delete(cleanup);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const TEST_PASSWORD_HASH_PREFIX = "$test$sha256$";
|
|
22
|
+
/**
|
|
23
|
+
* Intentionally fast for tests
|
|
24
|
+
*/
|
|
25
|
+
function createTestPasswordHash(password) {
|
|
26
|
+
return `${TEST_PASSWORD_HASH_PREFIX}${createHash("sha256").update(password.normalize("NFKC")).digest("hex")}`;
|
|
27
|
+
}
|
|
28
|
+
const testPassword = {
|
|
29
|
+
hash: async (password) => createTestPasswordHash(password),
|
|
30
|
+
verify: async ({ hash, password }) => hash === createTestPasswordHash(password)
|
|
31
|
+
};
|
|
32
|
+
async function getTestInstance(options, config) {
|
|
33
|
+
const testWith = config?.testWith || "sqlite";
|
|
34
|
+
const postgresSchema = testWith === "postgres" ? `ba_test_${randomUUID().replaceAll("-", "_")}` : void 0;
|
|
35
|
+
const quotePostgresIdentifier = (identifier) => `"${identifier.replaceAll("\"", "\"\"")}"`;
|
|
36
|
+
async function getPostgres() {
|
|
37
|
+
const { Kysely, PostgresDialect } = await import("kysely");
|
|
38
|
+
const { Pool } = await import("pg");
|
|
39
|
+
const pool = new Pool({
|
|
40
|
+
connectionString: "postgres://user:password@localhost:5432/better_auth",
|
|
41
|
+
options: postgresSchema ? `-c search_path=${postgresSchema},public` : void 0
|
|
42
|
+
});
|
|
43
|
+
if (postgresSchema) await pool.query(`CREATE SCHEMA IF NOT EXISTS ${quotePostgresIdentifier(postgresSchema)}`);
|
|
44
|
+
return new Kysely({ dialect: new PostgresDialect({ pool }) });
|
|
45
|
+
}
|
|
46
|
+
async function getSqlite() {
|
|
47
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
48
|
+
return new DatabaseSync(":memory:");
|
|
49
|
+
}
|
|
50
|
+
async function getMysql() {
|
|
51
|
+
const { Kysely, MysqlDialect } = await import("kysely");
|
|
52
|
+
const { createPool } = await import("mysql2/promise");
|
|
53
|
+
return new Kysely({ dialect: new MysqlDialect({ pool: createPool("mysql://user:password@localhost:3306/better_auth") }) });
|
|
54
|
+
}
|
|
55
|
+
async function mongodbClient() {
|
|
56
|
+
const { MongoClient } = await import("mongodb");
|
|
57
|
+
const dbClient = async (connectionString, dbName) => {
|
|
58
|
+
const client = new MongoClient(connectionString, {
|
|
59
|
+
serverSelectionTimeoutMS: 2e3,
|
|
60
|
+
connectTimeoutMS: 2e3
|
|
61
|
+
});
|
|
62
|
+
await client.connect();
|
|
63
|
+
return client.db(dbName);
|
|
64
|
+
};
|
|
65
|
+
return await dbClient("mongodb://127.0.0.1:27017", "better-auth");
|
|
66
|
+
}
|
|
67
|
+
const opts = {
|
|
68
|
+
socialProviders: {
|
|
69
|
+
github: {
|
|
70
|
+
clientId: "test",
|
|
71
|
+
clientSecret: "test"
|
|
72
|
+
},
|
|
73
|
+
google: {
|
|
74
|
+
clientId: "test",
|
|
75
|
+
clientSecret: "test"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
secret: "better-auth-secret-that-is-long-enough-for-validation-test",
|
|
79
|
+
database: testWith === "postgres" ? {
|
|
80
|
+
db: await getPostgres(),
|
|
81
|
+
type: "postgres",
|
|
82
|
+
transaction: config?.transaction
|
|
83
|
+
} : testWith === "mongodb" ? await Promise.all([mongodbClient(), await import("../adapters/mongodb-adapter/index.mjs")]).then(([db, { mongodbAdapter }]) => mongodbAdapter(db)) : testWith === "mysql" ? {
|
|
84
|
+
db: await getMysql(),
|
|
85
|
+
type: "mysql",
|
|
86
|
+
transaction: config?.transaction
|
|
87
|
+
} : await getSqlite(),
|
|
88
|
+
emailAndPassword: { enabled: true },
|
|
89
|
+
rateLimit: { enabled: false },
|
|
90
|
+
advanced: { cookies: {} },
|
|
91
|
+
logger: { level: "debug" }
|
|
92
|
+
};
|
|
93
|
+
const authOptions = {
|
|
94
|
+
baseURL: "http://localhost:" + (config?.port || 3e3),
|
|
95
|
+
...opts,
|
|
96
|
+
...options,
|
|
97
|
+
emailAndPassword: {
|
|
98
|
+
...opts.emailAndPassword,
|
|
99
|
+
...options?.emailAndPassword,
|
|
100
|
+
password: options?.emailAndPassword?.password ?? testPassword
|
|
101
|
+
},
|
|
102
|
+
plugins: [bearer(), ...options?.plugins || []]
|
|
103
|
+
};
|
|
104
|
+
if (testWith !== "mongodb") {
|
|
105
|
+
const { runMigrations } = await getMigrations({
|
|
106
|
+
...authOptions,
|
|
107
|
+
database: opts.database
|
|
108
|
+
});
|
|
109
|
+
await runMigrations();
|
|
110
|
+
}
|
|
111
|
+
const auth = betterAuth(authOptions);
|
|
112
|
+
const testUser = {
|
|
113
|
+
email: "test@test.com",
|
|
114
|
+
password: "test123456",
|
|
115
|
+
name: "test user",
|
|
116
|
+
...config?.testUser
|
|
117
|
+
};
|
|
118
|
+
async function createTestUser() {
|
|
119
|
+
if (config?.disableTestUser) return;
|
|
120
|
+
const dynamicBaseURL = isDynamicBaseURLConfig(auth.options.baseURL) ? auth.options.baseURL : void 0;
|
|
121
|
+
const host = (dynamicBaseURL?.allowedHosts.find((h) => !h.includes("*") && !h.includes("?")) ?? dynamicBaseURL?.allowedHosts[0])?.replace(/^https?:\/\//, "").split(/[/#]/)[0]?.replace(/\*/g, "test").replace(/\?/g, "x");
|
|
122
|
+
const headers = host ? new Headers({ host }) : void 0;
|
|
123
|
+
await auth.api.signUpEmail({
|
|
124
|
+
body: testUser,
|
|
125
|
+
headers
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
await createTestUser();
|
|
129
|
+
const cleanup = async () => {
|
|
130
|
+
if (testWith === "mongodb") {
|
|
131
|
+
await (await mongodbClient()).dropDatabase();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (testWith === "postgres") {
|
|
135
|
+
const postgres = await getPostgres();
|
|
136
|
+
if (postgresSchema) await sql.raw(`DROP SCHEMA IF EXISTS ${quotePostgresIdentifier(postgresSchema)} CASCADE`).execute(postgres);
|
|
137
|
+
else await sql`DROP SCHEMA public CASCADE; CREATE SCHEMA public;`.execute(postgres);
|
|
138
|
+
await postgres.destroy();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (testWith === "mysql") {
|
|
142
|
+
const mysql = await getMysql();
|
|
143
|
+
await sql`SET FOREIGN_KEY_CHECKS = 0;`.execute(mysql);
|
|
144
|
+
const tables = await mysql.introspection.getTables();
|
|
145
|
+
for (const table of tables) await mysql.deleteFrom(table.name).execute();
|
|
146
|
+
await sql`SET FOREIGN_KEY_CHECKS = 1;`.execute(mysql);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (testWith === "sqlite") {
|
|
150
|
+
(await getSqlite()).close();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
cleanupSet.add(cleanup);
|
|
155
|
+
const customFetchImpl = async (url, init) => {
|
|
156
|
+
const headers = init?.headers || {};
|
|
157
|
+
const storageHeaders = currentUserContextStorage.getStore()?.headers;
|
|
158
|
+
return auth.handler(new Request(url, init ? {
|
|
159
|
+
...init,
|
|
160
|
+
headers: new Headers({
|
|
161
|
+
...storageHeaders ? Object.fromEntries(storageHeaders.entries()) : {},
|
|
162
|
+
...headers instanceof Headers ? Object.fromEntries(headers.entries()) : typeof headers === "object" ? headers : {}
|
|
163
|
+
})
|
|
164
|
+
} : { headers }));
|
|
165
|
+
};
|
|
166
|
+
const clientBaseURL = isDynamicBaseURLConfig(options?.baseURL) ? getBaseURL("http://localhost:" + (config?.port || 3e3), options?.basePath || "/api/auth") : getBaseURL(typeof options?.baseURL === "string" ? options.baseURL : "http://localhost:" + (config?.port || 3e3), options?.basePath || "/api/auth");
|
|
167
|
+
const client = createAuthClient({
|
|
168
|
+
...config?.clientOptions,
|
|
169
|
+
baseURL: clientBaseURL,
|
|
170
|
+
fetchOptions: { customFetchImpl }
|
|
171
|
+
});
|
|
172
|
+
async function signInWithTestUser() {
|
|
173
|
+
if (config?.disableTestUser) throw new Error("Test user is disabled");
|
|
174
|
+
const headers = new Headers();
|
|
175
|
+
const setCookie = (name, value) => {
|
|
176
|
+
const current = headers.get("cookie");
|
|
177
|
+
headers.set("cookie", `${current || ""}; ${name}=${value}`);
|
|
178
|
+
};
|
|
179
|
+
const { data } = await client.signIn.email({
|
|
180
|
+
email: testUser.email,
|
|
181
|
+
password: testUser.password,
|
|
182
|
+
fetchOptions: { onSuccess(context) {
|
|
183
|
+
const signedCookie = parseSetCookieHeader(context.response.headers.get("set-cookie") || "").get("better-auth.session_token")?.value;
|
|
184
|
+
headers.set("cookie", `better-auth.session_token=${signedCookie}`);
|
|
185
|
+
} }
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
session: data.session,
|
|
189
|
+
user: data.user,
|
|
190
|
+
headers,
|
|
191
|
+
setCookie,
|
|
192
|
+
runWithUser: async (fn) => {
|
|
193
|
+
return currentUserContextStorage.run({ headers }, async () => {
|
|
194
|
+
await fn(headers);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
async function signInWithUser(email, password) {
|
|
200
|
+
const headers = new Headers();
|
|
201
|
+
const { data } = await client.signIn.email({
|
|
202
|
+
email,
|
|
203
|
+
password,
|
|
204
|
+
fetchOptions: { onSuccess(context) {
|
|
205
|
+
const signedCookie = parseSetCookieHeader(context.response.headers.get("set-cookie") || "").get("better-auth.session_token")?.value;
|
|
206
|
+
headers.set("cookie", `better-auth.session_token=${signedCookie}`);
|
|
207
|
+
} }
|
|
208
|
+
});
|
|
209
|
+
return {
|
|
210
|
+
res: data,
|
|
211
|
+
headers
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function sessionSetter(headers) {
|
|
215
|
+
return (context) => {
|
|
216
|
+
const header = context.response.headers.get("set-cookie");
|
|
217
|
+
if (header) {
|
|
218
|
+
const signedCookie = parseSetCookieHeader(header || "").get("better-auth.session_token")?.value;
|
|
219
|
+
headers.set("cookie", `better-auth.session_token=${signedCookie}`);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
auth,
|
|
225
|
+
client,
|
|
226
|
+
testUser,
|
|
227
|
+
signInWithTestUser,
|
|
228
|
+
signInWithUser,
|
|
229
|
+
cookieSetter: setCookieToHeader,
|
|
230
|
+
customFetchImpl,
|
|
231
|
+
sessionSetter,
|
|
232
|
+
db: await getAdapter(auth.options),
|
|
233
|
+
runWithUser: async (email, password, fn) => {
|
|
234
|
+
const { headers } = await signInWithUser(email, password);
|
|
235
|
+
return currentUserContextStorage.run({ headers }, async () => {
|
|
236
|
+
await fn(headers);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
export { getTestInstance };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { DBAdapter as DBAdapter$1, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, JoinOption, Where as Where$1 } from "@better-auth/core/db/adapter";
|
|
2
|
+
export { type DBAdapter$1 as DBAdapter, type DBAdapterInstance, type DBAdapterSchemaCreation, type DBTransactionAdapter, type JoinConfig, type JoinOption, type Where$1 as Where };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PrettifyDeep, UnionToIntersection } from "./helper.mjs";
|
|
2
|
+
import { Endpoint } from "better-call";
|
|
3
|
+
|
|
4
|
+
//#region src/types/api.d.ts
|
|
5
|
+
type FilteredAPI<API> = Omit<API, API extends { [key in infer K]: Endpoint } ? K extends string ? K extends "getSession" ? never : API[K]["options"]["metadata"] extends {
|
|
6
|
+
isAction: false;
|
|
7
|
+
} | {
|
|
8
|
+
scope: "http";
|
|
9
|
+
} ? K : never : never : never>;
|
|
10
|
+
type InferSessionAPI<API> = API extends {
|
|
11
|
+
[key: string]: infer E;
|
|
12
|
+
} ? UnionToIntersection<E extends Endpoint ? E["path"] extends "/get-session" ? {
|
|
13
|
+
getSession: <R extends boolean, H extends boolean = false>(context: {
|
|
14
|
+
headers: Headers;
|
|
15
|
+
query?: {
|
|
16
|
+
disableCookieCache?: boolean;
|
|
17
|
+
disableRefresh?: boolean;
|
|
18
|
+
} | undefined;
|
|
19
|
+
asResponse?: R | undefined;
|
|
20
|
+
returnHeaders?: H | undefined;
|
|
21
|
+
}) => false extends R ? H extends true ? Promise<{
|
|
22
|
+
headers: Headers;
|
|
23
|
+
response: PrettifyDeep<Awaited<ReturnType<E>>> | null;
|
|
24
|
+
}> : Promise<PrettifyDeep<Awaited<ReturnType<E>>> | null> : Promise<Response>;
|
|
25
|
+
} : never : never> : never;
|
|
26
|
+
type InferAPI<API> = InferSessionAPI<API> & FilteredAPI<API>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { FilteredAPI, InferAPI, InferSessionAPI };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InferAPI } from "./api.mjs";
|
|
2
|
+
import { InferPluginTypes, Session, User } from "./models.mjs";
|
|
3
|
+
import { InferPluginContext, InferPluginErrorCodes } from "./plugins.mjs";
|
|
4
|
+
import { router } from "../api/index.mjs";
|
|
5
|
+
import { AuthContext, BetterAuthOptions } from "@better-auth/core";
|
|
6
|
+
import { BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
7
|
+
|
|
8
|
+
//#region src/types/auth.d.ts
|
|
9
|
+
type Auth<Options extends BetterAuthOptions = BetterAuthOptions> = {
|
|
10
|
+
handler: (request: Request) => Promise<Response>;
|
|
11
|
+
/**
|
|
12
|
+
* Alias for {@link Auth.handler}.
|
|
13
|
+
*/
|
|
14
|
+
fetch: (request: Request) => Promise<Response>;
|
|
15
|
+
api: InferAPI<ReturnType<typeof router<Options>>["endpoints"]>;
|
|
16
|
+
options: Options;
|
|
17
|
+
$ERROR_CODES: InferPluginErrorCodes<Options> & typeof BASE_ERROR_CODES;
|
|
18
|
+
$context: Promise<AuthContext<Options> & InferPluginContext<Options>>;
|
|
19
|
+
/**
|
|
20
|
+
* Share types
|
|
21
|
+
*/
|
|
22
|
+
$Infer: InferPluginTypes<Options> extends {
|
|
23
|
+
Session: any;
|
|
24
|
+
} ? InferPluginTypes<Options> : {
|
|
25
|
+
Session: {
|
|
26
|
+
session: Session<Options["session"], Options["plugins"]>;
|
|
27
|
+
user: User<Options["user"], Options["plugins"]>;
|
|
28
|
+
};
|
|
29
|
+
} & InferPluginTypes<Options>;
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { Auth };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/types/helper.d.ts
|
|
2
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
3
|
+
type Prettify<T> = Omit<T, never>;
|
|
4
|
+
type PrettifyDeep<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? T[K] : T[K] extends object ? T[K] extends Array<any> ? T[K] : T[K] extends Date ? T[K] : PrettifyDeep<T[K]> : T[K] } & {};
|
|
5
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
6
|
+
type RequiredKeysOf<BaseType extends object> = Exclude<{ [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]> ? Key : never }[keyof BaseType], undefined>;
|
|
7
|
+
type HasRequiredKeys<BaseType> = IsAny<BaseType> extends true ? false : [BaseType] extends [object] ? RequiredKeysOf<BaseType & object> extends never ? false : true : false;
|
|
8
|
+
type StripEmptyObjects<T extends object> = { [K in keyof T]: T[K] };
|
|
9
|
+
/**
|
|
10
|
+
* Object merge replacing `Base`'s keys with `Override`'s.
|
|
11
|
+
* The naive `Omit<Base, keyof Override> & Override` form breaks under generics.
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/microsoft/TypeScript/issues/57466#issuecomment-1957988380
|
|
14
|
+
*/
|
|
15
|
+
type OverrideMerge<Base, Override> = Base extends unknown ? Override extends unknown ? Prettify<{ [K in keyof Base as K extends keyof Override ? never : K]: Base[K] } & Override> : never : never;
|
|
16
|
+
/**
|
|
17
|
+
* Extracts a Record-typed field from a plugin, guarding against `any`.
|
|
18
|
+
*/
|
|
19
|
+
type ExtractPluginField<T, Field extends string> = IsAny<T> extends true ? {} : T extends { [K in Field]?: Record<string, any> } ? T[Field] extends Record<string, any> ? T[Field] : {} : {};
|
|
20
|
+
/**
|
|
21
|
+
* Walks a plugin tuple with tail-recursive accumulator (TS 4.5+),
|
|
22
|
+
* extracting and intersecting the given field from each element.
|
|
23
|
+
*/
|
|
24
|
+
type InferPluginFieldFromTuple<T extends readonly unknown[], Field extends string, Acc = {}> = T extends readonly [infer Head, ...infer Tail] ? InferPluginFieldFromTuple<Tail, Field, Acc & ExtractPluginField<Head, Field>> : Acc;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection } from "./helper.mjs";
|
|
2
|
+
import { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientStore, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, InferSessionFromClient, InferUserFromClient, IsSignal, SessionQueryParams } from "../client/types.mjs";
|
|
3
|
+
import { DBAdapter, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, JoinOption, Where } from "./adapter.mjs";
|
|
4
|
+
import { FilteredAPI, InferAPI, InferSessionAPI } from "./api.mjs";
|
|
5
|
+
import { Account, AdditionalSessionFieldsInput, AdditionalUserFieldsInput, InferPluginTypes, RateLimit, Session, User, Verification } from "./models.mjs";
|
|
6
|
+
import { InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPluginIDs } from "./plugins.mjs";
|
|
7
|
+
import { Auth } from "./auth.mjs";
|
|
8
|
+
import { BetterAuthAdvancedOptions, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, StoreIdentifierOption, UserProvisioningSource, ValidateUserInfoAction, ValidateUserInfoMethod, ValidateUserInfoOAuthInfo, ValidateUserInfoResult, ValidateUserInfoSSOInfo, ValidateUserInfoSource } from "@better-auth/core";
|
|
9
|
+
export * from "@better-auth/core/social-providers";
|
|
10
|
+
export { Account, AdditionalSessionFieldsInput, AdditionalUserFieldsInput, Auth, type BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, type BetterAuthCookies, type BetterAuthOptions, type BetterAuthPlugin, type BetterAuthRateLimitOptions, ClientAtomListener, ClientStore, DBAdapter, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, ExtractPluginField, FilteredAPI, HasRequiredKeys, InferAPI, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPluginFieldFromTuple, InferPluginIDs, InferPluginTypes, InferSessionAPI, InferSessionFromClient, InferUserFromClient, IsAny, IsSignal, JoinConfig, JoinOption, OverrideMerge, Prettify, PrettifyDeep, RateLimit, RequiredKeysOf, Session, SessionQueryParams, type StoreIdentifierOption, StripEmptyObjects, UnionToIntersection, User, type UserProvisioningSource, type ValidateUserInfoAction, type ValidateUserInfoMethod, type ValidateUserInfoOAuthInfo, type ValidateUserInfoResult, type ValidateUserInfoSSOInfo, type ValidateUserInfoSource, Verification, Where };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExtractPluginField, InferPluginFieldFromTuple, UnionToIntersection } from "./helper.mjs";
|
|
2
|
+
import { BetterAuthOptions } from "@better-auth/core";
|
|
3
|
+
import { Account, InferDBFieldsFromOptionsInput, InferDBFieldsFromPluginsInput, RateLimit, Session as Session$1, User as User$1, Verification } from "@better-auth/core/db";
|
|
4
|
+
|
|
5
|
+
//#region src/types/models.d.ts
|
|
6
|
+
type AdditionalUserFieldsInput<Options extends BetterAuthOptions> = InferDBFieldsFromPluginsInput<"user", Options["plugins"]> & InferDBFieldsFromOptionsInput<Options["user"]>;
|
|
7
|
+
type AdditionalSessionFieldsInput<Options extends BetterAuthOptions> = InferDBFieldsFromPluginsInput<"session", Options["plugins"]> & InferDBFieldsFromOptionsInput<Options["session"]>;
|
|
8
|
+
type InferPluginTypes<O extends BetterAuthOptions> = O["plugins"] extends readonly [unknown, ...unknown[]] ? InferPluginFieldFromTuple<O["plugins"], "$Infer"> : O["plugins"] extends Array<infer P> ? UnionToIntersection<ExtractPluginField<P, "$Infer">> : {};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { type Account, AdditionalSessionFieldsInput, AdditionalUserFieldsInput, InferPluginTypes, type RateLimit, type Session$1 as Session, type User$1 as User, type Verification };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ExtractPluginField, InferPluginFieldFromTuple, UnionToIntersection } from "./helper.mjs";
|
|
2
|
+
import { AuthContext, BetterAuthOptions, BetterAuthPlugin } from "@better-auth/core";
|
|
3
|
+
import { BetterAuthPluginDBSchema } from "@better-auth/core/db";
|
|
4
|
+
|
|
5
|
+
//#region src/types/plugins.d.ts
|
|
6
|
+
type InferOptionSchema<S extends BetterAuthPluginDBSchema> = S extends Record<string, {
|
|
7
|
+
fields: infer Fields;
|
|
8
|
+
}> ? { [K in keyof S]?: {
|
|
9
|
+
modelName?: string | undefined;
|
|
10
|
+
fields?: { [P in keyof Fields]?: string } | undefined;
|
|
11
|
+
} } : never;
|
|
12
|
+
type InferPluginErrorCodes<O extends BetterAuthOptions> = O["plugins"] extends readonly [unknown, ...unknown[]] ? InferPluginFieldFromTuple<O["plugins"], "$ERROR_CODES"> : O["plugins"] extends Array<infer P> ? UnionToIntersection<ExtractPluginField<P, "$ERROR_CODES">> : {};
|
|
13
|
+
type InferPluginIDs<O extends BetterAuthOptions> = O["plugins"] extends Array<infer P> ? UnionToIntersection<P extends BetterAuthPlugin ? P["id"] : never> : never;
|
|
14
|
+
type ExtractInitContext<P extends BetterAuthPlugin> = P["init"] extends ((...args: any[]) => infer R) ? Awaited<R> extends {
|
|
15
|
+
context?: infer C;
|
|
16
|
+
} ? C extends Record<string, any> ? Omit<C, keyof AuthContext> : {} : {} : {};
|
|
17
|
+
type InferPluginContext<O extends BetterAuthOptions> = O["plugins"] extends Array<infer P> ? UnionToIntersection<P extends BetterAuthPlugin ? ExtractInitContext<P> : {}> : {};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPluginIDs };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
2
|
+
import { utf8ToBytes } from "@noble/hashes/utils.js";
|
|
3
|
+
//#region src/utils/hashing.ts
|
|
4
|
+
/**
|
|
5
|
+
* TS implementation of ERC-55 ("Mixed-case checksum address encoding") using @noble/hashes
|
|
6
|
+
* @param address - The address to convert to a checksum address
|
|
7
|
+
* @returns The checksummed address
|
|
8
|
+
*/
|
|
9
|
+
function toChecksumAddress(address) {
|
|
10
|
+
address = address.toLowerCase().replace("0x", "");
|
|
11
|
+
const hash = [...keccak_256(utf8ToBytes(address))].map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
12
|
+
let ret = "0x";
|
|
13
|
+
for (let i = 0; i < 40; i++) if (parseInt(hash[i], 16) >= 8) ret += address[i].toUpperCase();
|
|
14
|
+
else ret += address[i];
|
|
15
|
+
return ret;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { toChecksumAddress };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GenerateStateOptions, generateIdTokenNonce, generateState, parseState } from "../oauth2/state.mjs";
|
|
2
|
+
import { StateData, generateGenericState, parseGenericState } from "../state.mjs";
|
|
3
|
+
import { HIDE_METADATA } from "./hide-metadata.mjs";
|
|
4
|
+
import { getBaseURL, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes } from "./url.mjs";
|