@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,40 @@
|
|
|
1
|
+
//#region src/plugins/admin/schema.d.ts
|
|
2
|
+
declare const schema: {
|
|
3
|
+
user: {
|
|
4
|
+
fields: {
|
|
5
|
+
role: {
|
|
6
|
+
type: "string";
|
|
7
|
+
required: false;
|
|
8
|
+
input: false;
|
|
9
|
+
};
|
|
10
|
+
banned: {
|
|
11
|
+
type: "boolean";
|
|
12
|
+
defaultValue: false;
|
|
13
|
+
required: false;
|
|
14
|
+
input: false;
|
|
15
|
+
};
|
|
16
|
+
banReason: {
|
|
17
|
+
type: "string";
|
|
18
|
+
required: false;
|
|
19
|
+
input: false;
|
|
20
|
+
};
|
|
21
|
+
banExpires: {
|
|
22
|
+
type: "date";
|
|
23
|
+
required: false;
|
|
24
|
+
input: false;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
session: {
|
|
29
|
+
fields: {
|
|
30
|
+
impersonatedBy: {
|
|
31
|
+
type: "string";
|
|
32
|
+
required: false;
|
|
33
|
+
input: false;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
type AdminSchema = typeof schema;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { AdminSchema };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/plugins/admin/schema.ts
|
|
2
|
+
const schema = {
|
|
3
|
+
user: { fields: {
|
|
4
|
+
role: {
|
|
5
|
+
type: "string",
|
|
6
|
+
required: false,
|
|
7
|
+
input: false
|
|
8
|
+
},
|
|
9
|
+
banned: {
|
|
10
|
+
type: "boolean",
|
|
11
|
+
defaultValue: false,
|
|
12
|
+
required: false,
|
|
13
|
+
input: false
|
|
14
|
+
},
|
|
15
|
+
banReason: {
|
|
16
|
+
type: "string",
|
|
17
|
+
required: false,
|
|
18
|
+
input: false
|
|
19
|
+
},
|
|
20
|
+
banExpires: {
|
|
21
|
+
type: "date",
|
|
22
|
+
required: false,
|
|
23
|
+
input: false
|
|
24
|
+
}
|
|
25
|
+
} },
|
|
26
|
+
session: { fields: { impersonatedBy: {
|
|
27
|
+
type: "string",
|
|
28
|
+
required: false,
|
|
29
|
+
input: false
|
|
30
|
+
} } }
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { schema };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Session, User } from "../../types/models.mjs";
|
|
2
|
+
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
3
|
+
import { AccessControl, Role } from "../access/types.mjs";
|
|
4
|
+
import { AdminSchema } from "./schema.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/plugins/admin/types.d.ts
|
|
7
|
+
interface UserWithRole extends User {
|
|
8
|
+
role?: string | undefined;
|
|
9
|
+
banned: boolean | null;
|
|
10
|
+
banReason?: (string | null) | undefined;
|
|
11
|
+
banExpires?: (Date | null) | undefined;
|
|
12
|
+
}
|
|
13
|
+
interface SessionWithImpersonatedBy extends Session {
|
|
14
|
+
impersonatedBy?: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
interface AdminOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The default role for a user
|
|
19
|
+
*
|
|
20
|
+
* @default "user"
|
|
21
|
+
*/
|
|
22
|
+
defaultRole?: string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Roles that are considered admin roles.
|
|
25
|
+
*
|
|
26
|
+
* Any user role that isn't in this list, even if they have the permission,
|
|
27
|
+
* will not be considered an admin.
|
|
28
|
+
*
|
|
29
|
+
* @default ["admin"]
|
|
30
|
+
*/
|
|
31
|
+
adminRoles?: (string | string[]) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* A default ban reason
|
|
34
|
+
*
|
|
35
|
+
* By default, no reason is provided
|
|
36
|
+
*/
|
|
37
|
+
defaultBanReason?: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Number of seconds until the ban expires
|
|
40
|
+
*
|
|
41
|
+
* By default, the ban never expires
|
|
42
|
+
*/
|
|
43
|
+
defaultBanExpiresIn?: number | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Duration of the impersonation session in seconds
|
|
46
|
+
*
|
|
47
|
+
* By default, the impersonation session lasts 1 hour
|
|
48
|
+
*/
|
|
49
|
+
impersonationSessionDuration?: number | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Custom schema for the admin plugin
|
|
52
|
+
*/
|
|
53
|
+
schema?: InferOptionSchema<AdminSchema> | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Configure the roles and permissions for the admin
|
|
56
|
+
* plugin.
|
|
57
|
+
*/
|
|
58
|
+
ac?: AccessControl | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Custom permissions for roles.
|
|
61
|
+
*/
|
|
62
|
+
roles?: { [key in string]?: Role } | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* List of user ids that should have admin access
|
|
65
|
+
*
|
|
66
|
+
* If this is set, the `adminRole` option is ignored
|
|
67
|
+
*/
|
|
68
|
+
adminUserIds?: string[] | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Message to show when a user is banned
|
|
71
|
+
*
|
|
72
|
+
* By default, the message is "You have been banned from this application"
|
|
73
|
+
*/
|
|
74
|
+
bannedUserMessage?: string | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to allow impersonating other admins.
|
|
77
|
+
*
|
|
78
|
+
* @deprecated Use the `impersonate-admins` permission instead.
|
|
79
|
+
*
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
allowImpersonatingAdmins?: boolean | undefined;
|
|
83
|
+
}
|
|
84
|
+
type InferAdminRolesFromOption<O extends AdminOptions | undefined> = O extends {
|
|
85
|
+
roles: Record<string, unknown>;
|
|
86
|
+
} ? keyof O["roles"] : "user" | "admin";
|
|
87
|
+
//#endregion
|
|
88
|
+
export { AdminOptions, InferAdminRolesFromOption, SessionWithImpersonatedBy, UserWithRole };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { schema } from "./schema.mjs";
|
|
2
|
+
import { AnonymousOptions, AnonymousSession, UserWithAnonymous } from "./types.mjs";
|
|
3
|
+
import { anonymous } from "./index.mjs";
|
|
4
|
+
import { ANONYMOUS_ERROR_CODES } from "./error-codes.mjs";
|
|
5
|
+
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
6
|
+
|
|
7
|
+
//#region src/plugins/anonymous/client.d.ts
|
|
8
|
+
declare const anonymousClient: () => {
|
|
9
|
+
id: "anonymous";
|
|
10
|
+
version: string;
|
|
11
|
+
$InferServerPlugin: ReturnType<typeof anonymous>;
|
|
12
|
+
pathMethods: {
|
|
13
|
+
"/sign-in/anonymous": "POST";
|
|
14
|
+
"/delete-anonymous-user": "POST";
|
|
15
|
+
};
|
|
16
|
+
atomListeners: {
|
|
17
|
+
matcher: (path: string) => path is "/sign-in/anonymous";
|
|
18
|
+
signal: "$sessionSignal";
|
|
19
|
+
}[];
|
|
20
|
+
$ERROR_CODES: {
|
|
21
|
+
FAILED_TO_CREATE_USER: _$_better_auth_core_utils_error_codes0.RawError<"FAILED_TO_CREATE_USER">;
|
|
22
|
+
INVALID_EMAIL_FORMAT: _$_better_auth_core_utils_error_codes0.RawError<"INVALID_EMAIL_FORMAT">;
|
|
23
|
+
COULD_NOT_CREATE_SESSION: _$_better_auth_core_utils_error_codes0.RawError<"COULD_NOT_CREATE_SESSION">;
|
|
24
|
+
ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY: _$_better_auth_core_utils_error_codes0.RawError<"ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY">;
|
|
25
|
+
FAILED_TO_DELETE_ANONYMOUS_USER: _$_better_auth_core_utils_error_codes0.RawError<"FAILED_TO_DELETE_ANONYMOUS_USER">;
|
|
26
|
+
FAILED_TO_DELETE_ANONYMOUS_USER_SESSIONS: _$_better_auth_core_utils_error_codes0.RawError<"FAILED_TO_DELETE_ANONYMOUS_USER_SESSIONS">;
|
|
27
|
+
USER_IS_NOT_ANONYMOUS: _$_better_auth_core_utils_error_codes0.RawError<"USER_IS_NOT_ANONYMOUS">;
|
|
28
|
+
DELETE_ANONYMOUS_USER_DISABLED: _$_better_auth_core_utils_error_codes0.RawError<"DELETE_ANONYMOUS_USER_DISABLED">;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { anonymousClient };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
2
|
+
import { ANONYMOUS_ERROR_CODES } from "./error-codes.mjs";
|
|
3
|
+
//#region src/plugins/anonymous/client.ts
|
|
4
|
+
const anonymousClient = () => {
|
|
5
|
+
return {
|
|
6
|
+
id: "anonymous",
|
|
7
|
+
version: PACKAGE_VERSION,
|
|
8
|
+
$InferServerPlugin: {},
|
|
9
|
+
pathMethods: {
|
|
10
|
+
"/sign-in/anonymous": "POST",
|
|
11
|
+
"/delete-anonymous-user": "POST"
|
|
12
|
+
},
|
|
13
|
+
atomListeners: [{
|
|
14
|
+
matcher: (path) => path === "/sign-in/anonymous",
|
|
15
|
+
signal: "$sessionSignal"
|
|
16
|
+
}],
|
|
17
|
+
$ERROR_CODES: ANONYMOUS_ERROR_CODES
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { anonymousClient };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/anonymous/error-codes.d.ts
|
|
4
|
+
declare const ANONYMOUS_ERROR_CODES: {
|
|
5
|
+
FAILED_TO_CREATE_USER: _$_better_auth_core_utils_error_codes0.RawError<"FAILED_TO_CREATE_USER">;
|
|
6
|
+
INVALID_EMAIL_FORMAT: _$_better_auth_core_utils_error_codes0.RawError<"INVALID_EMAIL_FORMAT">;
|
|
7
|
+
COULD_NOT_CREATE_SESSION: _$_better_auth_core_utils_error_codes0.RawError<"COULD_NOT_CREATE_SESSION">;
|
|
8
|
+
ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY: _$_better_auth_core_utils_error_codes0.RawError<"ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY">;
|
|
9
|
+
FAILED_TO_DELETE_ANONYMOUS_USER: _$_better_auth_core_utils_error_codes0.RawError<"FAILED_TO_DELETE_ANONYMOUS_USER">;
|
|
10
|
+
FAILED_TO_DELETE_ANONYMOUS_USER_SESSIONS: _$_better_auth_core_utils_error_codes0.RawError<"FAILED_TO_DELETE_ANONYMOUS_USER_SESSIONS">;
|
|
11
|
+
USER_IS_NOT_ANONYMOUS: _$_better_auth_core_utils_error_codes0.RawError<"USER_IS_NOT_ANONYMOUS">;
|
|
12
|
+
DELETE_ANONYMOUS_USER_DISABLED: _$_better_auth_core_utils_error_codes0.RawError<"DELETE_ANONYMOUS_USER_DISABLED">;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ANONYMOUS_ERROR_CODES };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
|
|
2
|
+
//#region src/plugins/anonymous/error-codes.ts
|
|
3
|
+
const ANONYMOUS_ERROR_CODES = defineErrorCodes({
|
|
4
|
+
INVALID_EMAIL_FORMAT: "Email was not generated in a valid format",
|
|
5
|
+
FAILED_TO_CREATE_USER: "Failed to create user",
|
|
6
|
+
COULD_NOT_CREATE_SESSION: "Could not create session",
|
|
7
|
+
ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY: "Anonymous users cannot sign in again anonymously",
|
|
8
|
+
FAILED_TO_DELETE_ANONYMOUS_USER: "Failed to delete anonymous user",
|
|
9
|
+
FAILED_TO_DELETE_ANONYMOUS_USER_SESSIONS: "Failed to delete anonymous user sessions",
|
|
10
|
+
USER_IS_NOT_ANONYMOUS: "User is not anonymous",
|
|
11
|
+
DELETE_ANONYMOUS_USER_DISABLED: "Deleting anonymous users is disabled"
|
|
12
|
+
});
|
|
13
|
+
//#endregion
|
|
14
|
+
export { ANONYMOUS_ERROR_CODES };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { AnonymousOptions, AnonymousSession, UserWithAnonymous } from "./types.mjs";
|
|
2
|
+
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
3
|
+
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
4
|
+
import * as _$better_call0 from "better-call";
|
|
5
|
+
|
|
6
|
+
//#region src/plugins/anonymous/index.d.ts
|
|
7
|
+
declare module "@better-auth/core" {
|
|
8
|
+
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
9
|
+
anonymous: {
|
|
10
|
+
creator: typeof anonymous;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
declare const anonymous: (options?: AnonymousOptions | undefined) => {
|
|
15
|
+
id: "anonymous";
|
|
16
|
+
version: string;
|
|
17
|
+
endpoints: {
|
|
18
|
+
signInAnonymous: _$better_call0.StrictEndpoint<"/sign-in/anonymous", {
|
|
19
|
+
method: "POST";
|
|
20
|
+
metadata: {
|
|
21
|
+
openapi: {
|
|
22
|
+
description: string;
|
|
23
|
+
responses: {
|
|
24
|
+
200: {
|
|
25
|
+
description: string;
|
|
26
|
+
content: {
|
|
27
|
+
"application/json": {
|
|
28
|
+
schema: {
|
|
29
|
+
type: "object";
|
|
30
|
+
properties: {
|
|
31
|
+
user: {
|
|
32
|
+
$ref: string;
|
|
33
|
+
};
|
|
34
|
+
session: {
|
|
35
|
+
$ref: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}, {
|
|
46
|
+
token: string;
|
|
47
|
+
user: Record<string, any> & {
|
|
48
|
+
id: string;
|
|
49
|
+
createdAt: Date;
|
|
50
|
+
updatedAt: Date;
|
|
51
|
+
email: string;
|
|
52
|
+
emailVerified: boolean;
|
|
53
|
+
name: string;
|
|
54
|
+
image?: string | null | undefined;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
deleteAnonymousUser: _$better_call0.StrictEndpoint<"/delete-anonymous-user", {
|
|
58
|
+
method: "POST";
|
|
59
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<{
|
|
60
|
+
session: {
|
|
61
|
+
session: Record<string, any> & {
|
|
62
|
+
id: string;
|
|
63
|
+
createdAt: Date;
|
|
64
|
+
updatedAt: Date;
|
|
65
|
+
userId: string;
|
|
66
|
+
expiresAt: Date;
|
|
67
|
+
token: string;
|
|
68
|
+
ipAddress?: string | null | undefined;
|
|
69
|
+
userAgent?: string | null | undefined;
|
|
70
|
+
};
|
|
71
|
+
user: Record<string, any> & {
|
|
72
|
+
id: string;
|
|
73
|
+
createdAt: Date;
|
|
74
|
+
updatedAt: Date;
|
|
75
|
+
email: string;
|
|
76
|
+
emailVerified: boolean;
|
|
77
|
+
name: string;
|
|
78
|
+
image?: string | null | undefined;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}>>[];
|
|
82
|
+
metadata: {
|
|
83
|
+
openapi: {
|
|
84
|
+
description: string;
|
|
85
|
+
responses: {
|
|
86
|
+
200: {
|
|
87
|
+
description: string;
|
|
88
|
+
content: {
|
|
89
|
+
"application/json": {
|
|
90
|
+
schema: {
|
|
91
|
+
type: "object";
|
|
92
|
+
properties: {
|
|
93
|
+
success: {
|
|
94
|
+
type: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
"400": {
|
|
102
|
+
description: string;
|
|
103
|
+
content: {
|
|
104
|
+
"application/json": {
|
|
105
|
+
schema: {
|
|
106
|
+
type: "object";
|
|
107
|
+
properties: {
|
|
108
|
+
message: {
|
|
109
|
+
type: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
required: string[];
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
"500": {
|
|
118
|
+
description: string;
|
|
119
|
+
content: {
|
|
120
|
+
"application/json": {
|
|
121
|
+
schema: {
|
|
122
|
+
type: "object";
|
|
123
|
+
properties: {
|
|
124
|
+
message: {
|
|
125
|
+
type: string;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
required: string[];
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
}, {
|
|
137
|
+
success: boolean;
|
|
138
|
+
}>;
|
|
139
|
+
};
|
|
140
|
+
hooks: {
|
|
141
|
+
before: {
|
|
142
|
+
matcher(ctx: _$_better_auth_core0.HookEndpointContext): boolean;
|
|
143
|
+
handler: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<void>>;
|
|
144
|
+
}[];
|
|
145
|
+
after: {
|
|
146
|
+
matcher(ctx: _$_better_auth_core0.HookEndpointContext): boolean;
|
|
147
|
+
handler: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<void>>;
|
|
148
|
+
}[];
|
|
149
|
+
};
|
|
150
|
+
options: AnonymousOptions | undefined;
|
|
151
|
+
schema: {
|
|
152
|
+
user: {
|
|
153
|
+
fields: {
|
|
154
|
+
isAnonymous: {
|
|
155
|
+
type: "boolean";
|
|
156
|
+
required: false;
|
|
157
|
+
input: false;
|
|
158
|
+
defaultValue: false;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
$ERROR_CODES: {
|
|
164
|
+
FAILED_TO_CREATE_USER: _$_better_auth_core_utils_error_codes0.RawError<"FAILED_TO_CREATE_USER">;
|
|
165
|
+
INVALID_EMAIL_FORMAT: _$_better_auth_core_utils_error_codes0.RawError<"INVALID_EMAIL_FORMAT">;
|
|
166
|
+
COULD_NOT_CREATE_SESSION: _$_better_auth_core_utils_error_codes0.RawError<"COULD_NOT_CREATE_SESSION">;
|
|
167
|
+
ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY: _$_better_auth_core_utils_error_codes0.RawError<"ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY">;
|
|
168
|
+
FAILED_TO_DELETE_ANONYMOUS_USER: _$_better_auth_core_utils_error_codes0.RawError<"FAILED_TO_DELETE_ANONYMOUS_USER">;
|
|
169
|
+
FAILED_TO_DELETE_ANONYMOUS_USER_SESSIONS: _$_better_auth_core_utils_error_codes0.RawError<"FAILED_TO_DELETE_ANONYMOUS_USER_SESSIONS">;
|
|
170
|
+
USER_IS_NOT_ANONYMOUS: _$_better_auth_core_utils_error_codes0.RawError<"USER_IS_NOT_ANONYMOUS">;
|
|
171
|
+
DELETE_ANONYMOUS_USER_DISABLED: _$_better_auth_core_utils_error_codes0.RawError<"DELETE_ANONYMOUS_USER_DISABLED">;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
//#endregion
|
|
175
|
+
export { AnonymousOptions, AnonymousSession, UserWithAnonymous, anonymous };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { mergeSchema, parseUserOutput } from "../../db/schema.mjs";
|
|
2
|
+
import { parseSetCookieHeader } from "../../cookies/cookie-utils.mjs";
|
|
3
|
+
import { deleteSessionCookie, setSessionCookie } from "../../cookies/index.mjs";
|
|
4
|
+
import { addOAuthServerContext, getOAuthState } from "../../api/state/oauth.mjs";
|
|
5
|
+
import { getSessionFromCtx, sensitiveSessionMiddleware } from "../../api/routes/session.mjs";
|
|
6
|
+
import { APIError } from "../../api/index.mjs";
|
|
7
|
+
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
8
|
+
import { ANONYMOUS_ERROR_CODES } from "./error-codes.mjs";
|
|
9
|
+
import { schema } from "./schema.mjs";
|
|
10
|
+
import { generateId } from "@better-auth/core/utils/id";
|
|
11
|
+
import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
|
|
12
|
+
import * as z from "zod";
|
|
13
|
+
import { createPlaceholderEmail } from "@better-auth/core/utils/email";
|
|
14
|
+
//#region src/plugins/anonymous/index.ts
|
|
15
|
+
/**
|
|
16
|
+
* Resolves the anonymous session being upgraded during an account-link callback.
|
|
17
|
+
*
|
|
18
|
+
* The anonymous session is normally read from the request cookie. When the
|
|
19
|
+
* OAuth callback arrives without that cookie (for example Expo's in-app browser,
|
|
20
|
+
* which only carries the OAuth state, not the session cookie), the anonymous
|
|
21
|
+
* user id captured at sign-in is recovered from the server-only OAuth state
|
|
22
|
+
* instead. Returns `null` when there is no anonymous session to link.
|
|
23
|
+
*/
|
|
24
|
+
async function resolveAnonymousSession(ctx) {
|
|
25
|
+
const cookieSession = await getSessionFromCtx(ctx, { disableRefresh: true });
|
|
26
|
+
if (cookieSession?.user.isAnonymous) return {
|
|
27
|
+
session: cookieSession.session,
|
|
28
|
+
user: {
|
|
29
|
+
...cookieSession.user,
|
|
30
|
+
isAnonymous: true
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const anonymousUserId = (await getOAuthState())?.serverContext?.anonymousUserId;
|
|
34
|
+
if (typeof anonymousUserId !== "string") return null;
|
|
35
|
+
const user = await ctx.context.internalAdapter.findUserById(anonymousUserId);
|
|
36
|
+
if (!user?.isAnonymous) return null;
|
|
37
|
+
const [anonymousSession] = await ctx.context.internalAdapter.listSessions(user.id, { onlyActiveSessions: true });
|
|
38
|
+
if (!anonymousSession) return null;
|
|
39
|
+
return {
|
|
40
|
+
session: anonymousSession,
|
|
41
|
+
user: {
|
|
42
|
+
...user,
|
|
43
|
+
isAnonymous: true
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async function getAnonUserEmail(options) {
|
|
48
|
+
const customEmail = await options?.generateRandomEmail?.();
|
|
49
|
+
if (customEmail) {
|
|
50
|
+
if (!z.email().safeParse(customEmail).success) throw APIError.from("BAD_REQUEST", ANONYMOUS_ERROR_CODES.INVALID_EMAIL_FORMAT);
|
|
51
|
+
return customEmail;
|
|
52
|
+
}
|
|
53
|
+
const id = generateId();
|
|
54
|
+
if (options?.emailDomainName) return `temp-${id}@${options.emailDomainName}`;
|
|
55
|
+
return createPlaceholderEmail({
|
|
56
|
+
identifier: id,
|
|
57
|
+
namespace: "anonymous"
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const anonymous = (options) => {
|
|
61
|
+
return {
|
|
62
|
+
id: "anonymous",
|
|
63
|
+
version: PACKAGE_VERSION,
|
|
64
|
+
endpoints: {
|
|
65
|
+
signInAnonymous: createAuthEndpoint("/sign-in/anonymous", {
|
|
66
|
+
method: "POST",
|
|
67
|
+
metadata: { openapi: {
|
|
68
|
+
description: "Sign in anonymously",
|
|
69
|
+
responses: { 200: {
|
|
70
|
+
description: "Sign in anonymously",
|
|
71
|
+
content: { "application/json": { schema: {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: {
|
|
74
|
+
user: { $ref: "#/components/schemas/User" },
|
|
75
|
+
session: { $ref: "#/components/schemas/Session" }
|
|
76
|
+
}
|
|
77
|
+
} } }
|
|
78
|
+
} }
|
|
79
|
+
} }
|
|
80
|
+
}, async (ctx) => {
|
|
81
|
+
if ((await getSessionFromCtx(ctx, { disableRefresh: true }))?.user.isAnonymous) throw APIError.from("BAD_REQUEST", ANONYMOUS_ERROR_CODES.ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY);
|
|
82
|
+
const email = await getAnonUserEmail(options);
|
|
83
|
+
const name = await options?.generateName?.(ctx) || "Anonymous";
|
|
84
|
+
const newUser = await ctx.context.internalAdapter.createUser({
|
|
85
|
+
email,
|
|
86
|
+
emailVerified: false,
|
|
87
|
+
isAnonymous: true,
|
|
88
|
+
name,
|
|
89
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
90
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
91
|
+
}, { method: "anonymous" });
|
|
92
|
+
if (!newUser) throw APIError.from("INTERNAL_SERVER_ERROR", ANONYMOUS_ERROR_CODES.FAILED_TO_CREATE_USER);
|
|
93
|
+
const session = await ctx.context.internalAdapter.createSession(newUser.id);
|
|
94
|
+
if (!session) throw APIError.from("BAD_REQUEST", ANONYMOUS_ERROR_CODES.COULD_NOT_CREATE_SESSION);
|
|
95
|
+
await setSessionCookie(ctx, {
|
|
96
|
+
session,
|
|
97
|
+
user: newUser
|
|
98
|
+
});
|
|
99
|
+
return ctx.json({
|
|
100
|
+
token: session.token,
|
|
101
|
+
user: parseUserOutput(ctx.context.options, newUser)
|
|
102
|
+
});
|
|
103
|
+
}),
|
|
104
|
+
deleteAnonymousUser: createAuthEndpoint("/delete-anonymous-user", {
|
|
105
|
+
method: "POST",
|
|
106
|
+
use: [sensitiveSessionMiddleware],
|
|
107
|
+
metadata: { openapi: {
|
|
108
|
+
description: "Delete an anonymous user",
|
|
109
|
+
responses: {
|
|
110
|
+
200: {
|
|
111
|
+
description: "Anonymous user deleted",
|
|
112
|
+
content: { "application/json": { schema: {
|
|
113
|
+
type: "object",
|
|
114
|
+
properties: { success: { type: "boolean" } }
|
|
115
|
+
} } }
|
|
116
|
+
},
|
|
117
|
+
"400": {
|
|
118
|
+
description: "Anonymous user deletion is disabled",
|
|
119
|
+
content: { "application/json": {
|
|
120
|
+
schema: {
|
|
121
|
+
type: "object",
|
|
122
|
+
properties: { message: { type: "string" } }
|
|
123
|
+
},
|
|
124
|
+
required: ["message"]
|
|
125
|
+
} }
|
|
126
|
+
},
|
|
127
|
+
"500": {
|
|
128
|
+
description: "Internal server error",
|
|
129
|
+
content: { "application/json": { schema: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: { message: { type: "string" } },
|
|
132
|
+
required: ["message"]
|
|
133
|
+
} } }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} }
|
|
137
|
+
}, async (ctx) => {
|
|
138
|
+
const session = ctx.context.session;
|
|
139
|
+
if (options?.disableDeleteAnonymousUser) throw APIError.from("BAD_REQUEST", ANONYMOUS_ERROR_CODES.DELETE_ANONYMOUS_USER_DISABLED);
|
|
140
|
+
if (!session.user.isAnonymous) throw APIError.from("FORBIDDEN", ANONYMOUS_ERROR_CODES.USER_IS_NOT_ANONYMOUS);
|
|
141
|
+
try {
|
|
142
|
+
await ctx.context.internalAdapter.deleteUserSessions(session.user.id);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
ctx.context.logger.error("Failed to delete anonymous user sessions", error);
|
|
145
|
+
throw APIError.from("INTERNAL_SERVER_ERROR", ANONYMOUS_ERROR_CODES.FAILED_TO_DELETE_ANONYMOUS_USER_SESSIONS);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
await ctx.context.internalAdapter.deleteUser(session.user.id);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
ctx.context.logger.error("Failed to delete anonymous user", error);
|
|
151
|
+
throw APIError.from("INTERNAL_SERVER_ERROR", ANONYMOUS_ERROR_CODES.FAILED_TO_DELETE_ANONYMOUS_USER);
|
|
152
|
+
}
|
|
153
|
+
deleteSessionCookie(ctx);
|
|
154
|
+
return ctx.json({ success: true });
|
|
155
|
+
})
|
|
156
|
+
},
|
|
157
|
+
hooks: {
|
|
158
|
+
before: [{
|
|
159
|
+
matcher(ctx) {
|
|
160
|
+
return ctx.path === "/sign-in/social";
|
|
161
|
+
},
|
|
162
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
163
|
+
const session = await getSessionFromCtx(ctx, { disableRefresh: true });
|
|
164
|
+
if (!session?.user.isAnonymous) return;
|
|
165
|
+
await addOAuthServerContext({ anonymousUserId: session.user.id });
|
|
166
|
+
})
|
|
167
|
+
}],
|
|
168
|
+
after: [{
|
|
169
|
+
matcher(ctx) {
|
|
170
|
+
return ctx.path?.startsWith("/sign-in") || ctx.path?.startsWith("/sign-up") || ctx.path?.startsWith("/callback") || ctx.path?.startsWith("/magic-link/verify") || ctx.path?.startsWith("/email-otp/verify-email") || ctx.path?.startsWith("/one-tap/callback") || ctx.path?.startsWith("/passkey/verify-authentication") || ctx.path?.startsWith("/phone-number/verify") || ctx.path?.startsWith("/verify-email") || false;
|
|
171
|
+
},
|
|
172
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
173
|
+
const setCookie = ctx.context.responseHeaders?.get("set-cookie");
|
|
174
|
+
/**
|
|
175
|
+
* We can consider the user is about to sign in or sign up
|
|
176
|
+
* if the response contains a session token.
|
|
177
|
+
*/
|
|
178
|
+
const sessionTokenName = ctx.context.authCookies.sessionToken.name;
|
|
179
|
+
if (!parseSetCookieHeader(setCookie || "").get(sessionTokenName)?.value.split(".")[0]) return;
|
|
180
|
+
/**
|
|
181
|
+
* Make sure the user had an anonymous session. Falls back to the
|
|
182
|
+
* server-only OAuth state when the callback arrives without the
|
|
183
|
+
* anonymous session cookie (for example Expo).
|
|
184
|
+
*/
|
|
185
|
+
const session = await resolveAnonymousSession(ctx);
|
|
186
|
+
if (!session) return;
|
|
187
|
+
if (ctx.path === "/sign-in/anonymous" && !ctx.context.newSession) throw APIError.from("BAD_REQUEST", ANONYMOUS_ERROR_CODES.ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY);
|
|
188
|
+
const newSession = ctx.context.newSession;
|
|
189
|
+
if (!newSession) return;
|
|
190
|
+
if (options?.onLinkAccount) await options.onLinkAccount({
|
|
191
|
+
anonymousUser: {
|
|
192
|
+
session: session.session,
|
|
193
|
+
user: session.user
|
|
194
|
+
},
|
|
195
|
+
newUser: newSession,
|
|
196
|
+
ctx
|
|
197
|
+
});
|
|
198
|
+
const newSessionUser = newSession.user;
|
|
199
|
+
const isSameUser = newSessionUser?.id === session.user.id;
|
|
200
|
+
const newSessionIsAnonymous = Boolean(newSessionUser?.isAnonymous);
|
|
201
|
+
if (options?.disableDeleteAnonymousUser || isSameUser || newSessionIsAnonymous) return;
|
|
202
|
+
try {
|
|
203
|
+
await ctx.context.internalAdapter.deleteUser(session.user.id);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
ctx.context.logger.error("Failed to clean up anonymous user during post-link cleanup", {
|
|
206
|
+
anonymousUserId: session.user.id,
|
|
207
|
+
error
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
}]
|
|
212
|
+
},
|
|
213
|
+
options,
|
|
214
|
+
schema: mergeSchema(schema, options?.schema),
|
|
215
|
+
$ERROR_CODES: ANONYMOUS_ERROR_CODES
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
//#endregion
|
|
219
|
+
export { anonymous };
|