@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,98 @@
|
|
|
1
|
+
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
2
|
+
import { createAuthMiddleware } from "@better-auth/core/api";
|
|
3
|
+
//#region src/plugins/last-login-method/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Plugin to track the last used login method
|
|
6
|
+
*/
|
|
7
|
+
const lastLoginMethod = (userConfig) => {
|
|
8
|
+
const defaultResolveMethod = (ctx) => {
|
|
9
|
+
const path = ctx.path;
|
|
10
|
+
if (!path) return null;
|
|
11
|
+
if (path.startsWith("/callback/")) return ctx.params?.id || path.split("/").pop();
|
|
12
|
+
if (path === "/sign-in/email" || path === "/sign-up/email") return "email";
|
|
13
|
+
if (path.includes("siwe")) return "siwe";
|
|
14
|
+
if (path.includes("/passkey/verify-authentication")) return "passkey";
|
|
15
|
+
if (path.startsWith("/magic-link/verify")) return "magic-link";
|
|
16
|
+
if (path === "/sign-in/email-otp") return "email-otp";
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
19
|
+
const getResolveContext = (ctx) => {
|
|
20
|
+
return ctx.path ? ctx : {
|
|
21
|
+
...ctx,
|
|
22
|
+
path: ""
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const resolveMethod = (ctx) => {
|
|
26
|
+
const resolveContext = getResolveContext(ctx);
|
|
27
|
+
return config.customResolveMethod?.(resolveContext) ?? defaultResolveMethod(resolveContext);
|
|
28
|
+
};
|
|
29
|
+
const config = {
|
|
30
|
+
cookieName: "better-auth.last_used_login_method",
|
|
31
|
+
maxAge: 3600 * 24 * 30,
|
|
32
|
+
...userConfig
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
id: "last-login-method",
|
|
36
|
+
version: PACKAGE_VERSION,
|
|
37
|
+
init(ctx) {
|
|
38
|
+
return { options: { databaseHooks: {
|
|
39
|
+
user: { create: { async before(user, context) {
|
|
40
|
+
if (!config.storeInDatabase) return;
|
|
41
|
+
if (!context) return;
|
|
42
|
+
const lastUsedLoginMethod = resolveMethod(context);
|
|
43
|
+
if (lastUsedLoginMethod) return { data: {
|
|
44
|
+
...user,
|
|
45
|
+
lastLoginMethod: lastUsedLoginMethod
|
|
46
|
+
} };
|
|
47
|
+
} } },
|
|
48
|
+
session: { create: { async after(session, context) {
|
|
49
|
+
if (!config.storeInDatabase) return;
|
|
50
|
+
if (!context) return;
|
|
51
|
+
const lastUsedLoginMethod = resolveMethod(context);
|
|
52
|
+
if (lastUsedLoginMethod && session?.userId) try {
|
|
53
|
+
await ctx.internalAdapter.updateUser(session.userId, { lastLoginMethod: lastUsedLoginMethod });
|
|
54
|
+
} catch (error) {
|
|
55
|
+
ctx.logger.error("Failed to update lastLoginMethod", error);
|
|
56
|
+
}
|
|
57
|
+
} } }
|
|
58
|
+
} } };
|
|
59
|
+
},
|
|
60
|
+
hooks: { after: [{
|
|
61
|
+
matcher() {
|
|
62
|
+
return true;
|
|
63
|
+
},
|
|
64
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
65
|
+
const lastUsedLoginMethod = resolveMethod(ctx);
|
|
66
|
+
if (lastUsedLoginMethod) {
|
|
67
|
+
const setCookieHeaders = ctx.context.responseHeaders?.getSetCookie?.() || [];
|
|
68
|
+
const sessionTokenName = ctx.context.authCookies.sessionToken.name;
|
|
69
|
+
if (setCookieHeaders.some((cookie) => cookie.includes(sessionTokenName))) {
|
|
70
|
+
const cookieAttributes = {
|
|
71
|
+
...ctx.context.authCookies.sessionToken.attributes,
|
|
72
|
+
maxAge: config.maxAge,
|
|
73
|
+
httpOnly: false
|
|
74
|
+
};
|
|
75
|
+
let isPermitted = true;
|
|
76
|
+
if (config.beforeStoreCookie) try {
|
|
77
|
+
isPermitted = await config.beforeStoreCookie(ctx, lastUsedLoginMethod);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (ctx.context.logger) ctx.context.logger.error?.("[LastLoginMethod] Error in beforeStoreCookie hook", error);
|
|
80
|
+
isPermitted = false;
|
|
81
|
+
}
|
|
82
|
+
if (!isPermitted) return;
|
|
83
|
+
ctx.setCookie(config.cookieName, lastUsedLoginMethod, cookieAttributes);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}] },
|
|
88
|
+
schema: config.storeInDatabase ? { user: { fields: { lastLoginMethod: {
|
|
89
|
+
type: "string",
|
|
90
|
+
input: false,
|
|
91
|
+
required: false,
|
|
92
|
+
fieldName: config.schema?.user?.lastLoginMethod || "lastLoginMethod"
|
|
93
|
+
} } } } : void 0,
|
|
94
|
+
options: userConfig
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
//#endregion
|
|
98
|
+
export { lastLoginMethod };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { magicLink } from "./index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/magic-link/client.d.ts
|
|
4
|
+
declare const magicLinkClient: () => {
|
|
5
|
+
id: "magic-link";
|
|
6
|
+
version: string;
|
|
7
|
+
$InferServerPlugin: ReturnType<typeof magicLink>;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { magicLinkClient };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
2
|
+
//#region src/plugins/magic-link/client.ts
|
|
3
|
+
const magicLinkClient = () => {
|
|
4
|
+
return {
|
|
5
|
+
id: "magic-link",
|
|
6
|
+
version: PACKAGE_VERSION,
|
|
7
|
+
$InferServerPlugin: {}
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { magicLinkClient };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { Awaitable, GenericEndpointContext } from "@better-auth/core";
|
|
2
|
+
import * as _$better_call0 from "better-call";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/magic-link/index.d.ts
|
|
6
|
+
declare module "@better-auth/core" {
|
|
7
|
+
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
8
|
+
"magic-link": {
|
|
9
|
+
creator: typeof magicLink;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
interface MagicLinkOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Time in seconds until the magic link expires.
|
|
16
|
+
* @default (60 * 5) // 5 minutes
|
|
17
|
+
*/
|
|
18
|
+
expiresIn?: number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Allowed attempts for verifying the magic link token.
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Multi-attempt verification is no longer supported. Each
|
|
23
|
+
* magic link token is consumed atomically on the first verification call,
|
|
24
|
+
* so a given token mints at most one session regardless of this value
|
|
25
|
+
* The option is kept for source compatibility and may be removed in a future
|
|
26
|
+
* major; any value other than `1` is ignored and emits a `console.warn` at
|
|
27
|
+
* plugin construction.
|
|
28
|
+
*
|
|
29
|
+
* @default 1
|
|
30
|
+
*/
|
|
31
|
+
allowedAttempts?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Send magic link implementation.
|
|
34
|
+
*/
|
|
35
|
+
sendMagicLink: (data: {
|
|
36
|
+
email: string;
|
|
37
|
+
url: string;
|
|
38
|
+
token: string;
|
|
39
|
+
metadata?: Record<string, any>;
|
|
40
|
+
}, ctx?: GenericEndpointContext | undefined) => Awaitable<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Disable sign up if user is not found.
|
|
43
|
+
*
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
disableSignUp?: boolean | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Rate limit configuration.
|
|
49
|
+
*
|
|
50
|
+
* @default {
|
|
51
|
+
* window: 60,
|
|
52
|
+
* max: 5,
|
|
53
|
+
* }
|
|
54
|
+
*/
|
|
55
|
+
rateLimit?: {
|
|
56
|
+
window: number;
|
|
57
|
+
max: number;
|
|
58
|
+
} | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Custom function to generate a token
|
|
61
|
+
*/
|
|
62
|
+
generateToken?: ((email: string) => Awaitable<string>) | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* This option allows you to configure how the token is stored in your database.
|
|
65
|
+
* Note: This will not affect the token that's sent, it will only affect the token stored in your database.
|
|
66
|
+
*
|
|
67
|
+
* @default "plain"
|
|
68
|
+
*/
|
|
69
|
+
storeToken?: ("plain" | "hashed" | {
|
|
70
|
+
type: "custom-hasher";
|
|
71
|
+
hash: (token: string) => Promise<string>;
|
|
72
|
+
}) | undefined;
|
|
73
|
+
}
|
|
74
|
+
declare const magicLink: (options: MagicLinkOptions) => {
|
|
75
|
+
id: "magic-link";
|
|
76
|
+
version: string;
|
|
77
|
+
endpoints: {
|
|
78
|
+
/**
|
|
79
|
+
* ### Endpoint
|
|
80
|
+
*
|
|
81
|
+
* POST `/sign-in/magic-link`
|
|
82
|
+
*
|
|
83
|
+
* ### API Methods
|
|
84
|
+
*
|
|
85
|
+
* **server:**
|
|
86
|
+
* `auth.api.signInMagicLink`
|
|
87
|
+
*
|
|
88
|
+
* **client:**
|
|
89
|
+
* `authClient.signIn.magicLink`
|
|
90
|
+
*
|
|
91
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/sign-in#api-method-sign-in-magic-link)
|
|
92
|
+
*/
|
|
93
|
+
signInMagicLink: _$better_call0.StrictEndpoint<"/sign-in/magic-link", {
|
|
94
|
+
method: "POST";
|
|
95
|
+
requireHeaders: true;
|
|
96
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<void>>[];
|
|
97
|
+
body: z.ZodObject<{
|
|
98
|
+
email: z.ZodEmail;
|
|
99
|
+
name: z.ZodOptional<z.ZodString>;
|
|
100
|
+
callbackURL: z.ZodOptional<z.ZodString>;
|
|
101
|
+
newUserCallbackURL: z.ZodOptional<z.ZodString>;
|
|
102
|
+
errorCallbackURL: z.ZodOptional<z.ZodString>;
|
|
103
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
metadata: {
|
|
106
|
+
openapi: {
|
|
107
|
+
operationId: string;
|
|
108
|
+
description: string;
|
|
109
|
+
responses: {
|
|
110
|
+
200: {
|
|
111
|
+
description: string;
|
|
112
|
+
content: {
|
|
113
|
+
"application/json": {
|
|
114
|
+
schema: {
|
|
115
|
+
type: "object";
|
|
116
|
+
properties: {
|
|
117
|
+
status: {
|
|
118
|
+
type: string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
}, {
|
|
129
|
+
status: boolean;
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* ### Endpoint
|
|
133
|
+
*
|
|
134
|
+
* GET `/magic-link/verify`
|
|
135
|
+
*
|
|
136
|
+
* ### API Methods
|
|
137
|
+
*
|
|
138
|
+
* **server:**
|
|
139
|
+
* `auth.api.magicLinkVerify`
|
|
140
|
+
*
|
|
141
|
+
* **client:**
|
|
142
|
+
* `authClient.magicLink.verify`
|
|
143
|
+
*
|
|
144
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/magic-link#api-method-magic-link-verify)
|
|
145
|
+
*/
|
|
146
|
+
magicLinkVerify: _$better_call0.StrictEndpoint<"/magic-link/verify", {
|
|
147
|
+
method: "GET";
|
|
148
|
+
query: z.ZodObject<{
|
|
149
|
+
token: z.ZodString;
|
|
150
|
+
callbackURL: z.ZodOptional<z.ZodString>;
|
|
151
|
+
errorCallbackURL: z.ZodOptional<z.ZodString>;
|
|
152
|
+
newUserCallbackURL: z.ZodOptional<z.ZodString>;
|
|
153
|
+
}, z.core.$strip>;
|
|
154
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<void>>[];
|
|
155
|
+
requireHeaders: true;
|
|
156
|
+
metadata: {
|
|
157
|
+
openapi: {
|
|
158
|
+
operationId: string;
|
|
159
|
+
description: string;
|
|
160
|
+
responses: {
|
|
161
|
+
200: {
|
|
162
|
+
description: string;
|
|
163
|
+
content: {
|
|
164
|
+
"application/json": {
|
|
165
|
+
schema: {
|
|
166
|
+
type: "object";
|
|
167
|
+
properties: {
|
|
168
|
+
session: {
|
|
169
|
+
$ref: string;
|
|
170
|
+
};
|
|
171
|
+
user: {
|
|
172
|
+
$ref: string;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
}, {
|
|
183
|
+
token: string;
|
|
184
|
+
user: {
|
|
185
|
+
id: string;
|
|
186
|
+
createdAt: Date;
|
|
187
|
+
updatedAt: Date;
|
|
188
|
+
email: string;
|
|
189
|
+
emailVerified: boolean;
|
|
190
|
+
name: string;
|
|
191
|
+
image?: string | null | undefined;
|
|
192
|
+
};
|
|
193
|
+
session: {
|
|
194
|
+
id: string;
|
|
195
|
+
createdAt: Date;
|
|
196
|
+
updatedAt: Date;
|
|
197
|
+
userId: string;
|
|
198
|
+
expiresAt: Date;
|
|
199
|
+
token: string;
|
|
200
|
+
ipAddress?: string | null | undefined;
|
|
201
|
+
userAgent?: string | null | undefined;
|
|
202
|
+
};
|
|
203
|
+
}>;
|
|
204
|
+
};
|
|
205
|
+
rateLimit: {
|
|
206
|
+
pathMatcher(path: string): boolean;
|
|
207
|
+
window: number;
|
|
208
|
+
max: number;
|
|
209
|
+
}[];
|
|
210
|
+
options: MagicLinkOptions;
|
|
211
|
+
};
|
|
212
|
+
//#endregion
|
|
213
|
+
export { MagicLinkOptions, magicLink };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { isAPIError } from "../../utils/is-api-error.mjs";
|
|
2
|
+
import { formCsrfMiddleware, originCheck } from "../../api/middlewares/origin-check.mjs";
|
|
3
|
+
import { parseSessionOutput, parseUserOutput } from "../../db/schema.mjs";
|
|
4
|
+
import { generateRandomString } from "../../crypto/random.mjs";
|
|
5
|
+
import { setSessionCookie } from "../../cookies/index.mjs";
|
|
6
|
+
import { revokeUnprovenAccountAccess } from "../../db/revoke-unproven-account-access.mjs";
|
|
7
|
+
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
8
|
+
import { defaultKeyHasher } from "./utils.mjs";
|
|
9
|
+
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
10
|
+
import * as z from "zod";
|
|
11
|
+
//#region src/plugins/magic-link/index.ts
|
|
12
|
+
const signInMagicLinkBodySchema = z.object({
|
|
13
|
+
email: z.email().meta({ description: "Email address to send the magic link" }),
|
|
14
|
+
name: z.string().meta({ description: "User display name. Only used if the user is registering for the first time. Eg: \"my-name\"" }).optional(),
|
|
15
|
+
callbackURL: z.string().meta({ description: "URL to redirect after magic link verification" }).optional(),
|
|
16
|
+
newUserCallbackURL: z.string().meta({ description: "URL to redirect after new user signup. Only used if the user is registering for the first time." }).optional(),
|
|
17
|
+
errorCallbackURL: z.string().meta({ description: "URL to redirect after error." }).optional(),
|
|
18
|
+
metadata: z.record(z.string(), z.any()).meta({ description: "Additional metadata to pass to sendMagicLink." }).optional()
|
|
19
|
+
});
|
|
20
|
+
const magicLinkVerifyQuerySchema = z.object({
|
|
21
|
+
token: z.string().meta({ description: "Verification token" }),
|
|
22
|
+
callbackURL: z.string().meta({ description: "URL to redirect after magic link verification, if not provided the user will be redirected to the root URL. Eg: \"/dashboard\"" }).optional(),
|
|
23
|
+
errorCallbackURL: z.string().meta({ description: "URL to redirect after error." }).optional(),
|
|
24
|
+
newUserCallbackURL: z.string().meta({ description: "URL to redirect after new user signup. Only used if the user is registering for the first time." }).optional()
|
|
25
|
+
});
|
|
26
|
+
const magicLink = (options) => {
|
|
27
|
+
const opts = {
|
|
28
|
+
storeToken: "plain",
|
|
29
|
+
allowedAttempts: 1,
|
|
30
|
+
...options
|
|
31
|
+
};
|
|
32
|
+
if (options.allowedAttempts !== void 0 && options.allowedAttempts !== 1) console.warn("[better-auth/magic-link] `allowedAttempts` is ignored: tokens are consumed atomically on the first verification call. Any value other than `1` has no effect; remove the option to silence this warning.");
|
|
33
|
+
async function storeToken(ctx, token) {
|
|
34
|
+
if (opts.storeToken === "hashed") return await defaultKeyHasher(token);
|
|
35
|
+
if (typeof opts.storeToken === "object" && "type" in opts.storeToken && opts.storeToken.type === "custom-hasher") return await opts.storeToken.hash(token);
|
|
36
|
+
return token;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
id: "magic-link",
|
|
40
|
+
version: PACKAGE_VERSION,
|
|
41
|
+
endpoints: {
|
|
42
|
+
/**
|
|
43
|
+
* ### Endpoint
|
|
44
|
+
*
|
|
45
|
+
* POST `/sign-in/magic-link`
|
|
46
|
+
*
|
|
47
|
+
* ### API Methods
|
|
48
|
+
*
|
|
49
|
+
* **server:**
|
|
50
|
+
* `auth.api.signInMagicLink`
|
|
51
|
+
*
|
|
52
|
+
* **client:**
|
|
53
|
+
* `authClient.signIn.magicLink`
|
|
54
|
+
*
|
|
55
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/sign-in#api-method-sign-in-magic-link)
|
|
56
|
+
*/
|
|
57
|
+
signInMagicLink: createAuthEndpoint("/sign-in/magic-link", {
|
|
58
|
+
method: "POST",
|
|
59
|
+
requireHeaders: true,
|
|
60
|
+
use: [formCsrfMiddleware],
|
|
61
|
+
body: signInMagicLinkBodySchema,
|
|
62
|
+
metadata: { openapi: {
|
|
63
|
+
operationId: "signInWithMagicLink",
|
|
64
|
+
description: "Sign in with magic link",
|
|
65
|
+
responses: { 200: {
|
|
66
|
+
description: "Success",
|
|
67
|
+
content: { "application/json": { schema: {
|
|
68
|
+
type: "object",
|
|
69
|
+
properties: { status: { type: "boolean" } }
|
|
70
|
+
} } }
|
|
71
|
+
} }
|
|
72
|
+
} }
|
|
73
|
+
}, async (ctx) => {
|
|
74
|
+
const { email, metadata } = ctx.body;
|
|
75
|
+
const verificationToken = opts?.generateToken ? await opts.generateToken(email) : generateRandomString(32, "a-z", "A-Z");
|
|
76
|
+
const storedToken = await storeToken(ctx, verificationToken);
|
|
77
|
+
await ctx.context.internalAdapter.createVerificationValue({
|
|
78
|
+
identifier: storedToken,
|
|
79
|
+
value: JSON.stringify({
|
|
80
|
+
email,
|
|
81
|
+
name: ctx.body.name
|
|
82
|
+
}),
|
|
83
|
+
expiresAt: new Date(Date.now() + (opts.expiresIn || 300) * 1e3)
|
|
84
|
+
});
|
|
85
|
+
const realBaseURL = new URL(ctx.context.baseURL);
|
|
86
|
+
const pathname = realBaseURL.pathname === "/" ? "" : realBaseURL.pathname;
|
|
87
|
+
const basePath = pathname ? "" : ctx.context.options.basePath || "";
|
|
88
|
+
const url = new URL(`${pathname}${basePath}/magic-link/verify`, realBaseURL.origin);
|
|
89
|
+
url.searchParams.set("token", verificationToken);
|
|
90
|
+
url.searchParams.set("callbackURL", ctx.body.callbackURL || "/");
|
|
91
|
+
if (ctx.body.newUserCallbackURL) url.searchParams.set("newUserCallbackURL", ctx.body.newUserCallbackURL);
|
|
92
|
+
if (ctx.body.errorCallbackURL) url.searchParams.set("errorCallbackURL", ctx.body.errorCallbackURL);
|
|
93
|
+
await options.sendMagicLink({
|
|
94
|
+
email,
|
|
95
|
+
url: url.toString(),
|
|
96
|
+
token: verificationToken,
|
|
97
|
+
metadata
|
|
98
|
+
}, ctx);
|
|
99
|
+
return ctx.json({ status: true });
|
|
100
|
+
}),
|
|
101
|
+
/**
|
|
102
|
+
* ### Endpoint
|
|
103
|
+
*
|
|
104
|
+
* GET `/magic-link/verify`
|
|
105
|
+
*
|
|
106
|
+
* ### API Methods
|
|
107
|
+
*
|
|
108
|
+
* **server:**
|
|
109
|
+
* `auth.api.magicLinkVerify`
|
|
110
|
+
*
|
|
111
|
+
* **client:**
|
|
112
|
+
* `authClient.magicLink.verify`
|
|
113
|
+
*
|
|
114
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/magic-link#api-method-magic-link-verify)
|
|
115
|
+
*/
|
|
116
|
+
magicLinkVerify: createAuthEndpoint("/magic-link/verify", {
|
|
117
|
+
method: "GET",
|
|
118
|
+
query: magicLinkVerifyQuerySchema,
|
|
119
|
+
use: [
|
|
120
|
+
originCheck((ctx) => {
|
|
121
|
+
return ctx.query.callbackURL ? decodeURIComponent(ctx.query.callbackURL) : "/";
|
|
122
|
+
}),
|
|
123
|
+
originCheck((ctx) => {
|
|
124
|
+
return ctx.query.newUserCallbackURL ? decodeURIComponent(ctx.query.newUserCallbackURL) : "/";
|
|
125
|
+
}),
|
|
126
|
+
originCheck((ctx) => {
|
|
127
|
+
return ctx.query.errorCallbackURL ? decodeURIComponent(ctx.query.errorCallbackURL) : "/";
|
|
128
|
+
})
|
|
129
|
+
],
|
|
130
|
+
requireHeaders: true,
|
|
131
|
+
metadata: { openapi: {
|
|
132
|
+
operationId: "verifyMagicLink",
|
|
133
|
+
description: "Verify magic link",
|
|
134
|
+
responses: { 200: {
|
|
135
|
+
description: "Success",
|
|
136
|
+
content: { "application/json": { schema: {
|
|
137
|
+
type: "object",
|
|
138
|
+
properties: {
|
|
139
|
+
session: { $ref: "#/components/schemas/Session" },
|
|
140
|
+
user: { $ref: "#/components/schemas/User" }
|
|
141
|
+
}
|
|
142
|
+
} } }
|
|
143
|
+
} }
|
|
144
|
+
} }
|
|
145
|
+
}, async (ctx) => {
|
|
146
|
+
const token = ctx.query.token;
|
|
147
|
+
const callbackURL = new URL(ctx.query.callbackURL ? decodeURIComponent(ctx.query.callbackURL) : "/", ctx.context.baseURL).toString();
|
|
148
|
+
const errorCallbackURL = new URL(ctx.query.errorCallbackURL ? decodeURIComponent(ctx.query.errorCallbackURL) : callbackURL, ctx.context.baseURL);
|
|
149
|
+
function redirectWithError(error, description) {
|
|
150
|
+
errorCallbackURL.searchParams.set("error", error);
|
|
151
|
+
if (description) errorCallbackURL.searchParams.set("error_description", description);
|
|
152
|
+
throw ctx.redirect(errorCallbackURL.toString());
|
|
153
|
+
}
|
|
154
|
+
const newUserCallbackURL = new URL(ctx.query.newUserCallbackURL ? decodeURIComponent(ctx.query.newUserCallbackURL) : callbackURL, ctx.context.baseURL).toString();
|
|
155
|
+
const storedToken = await storeToken(ctx, token);
|
|
156
|
+
const tokenValue = await ctx.context.internalAdapter.consumeVerificationValue(storedToken);
|
|
157
|
+
if (!tokenValue) redirectWithError("INVALID_TOKEN");
|
|
158
|
+
const { email, name } = JSON.parse(tokenValue.value);
|
|
159
|
+
let isNewUser = false;
|
|
160
|
+
let user = await ctx.context.internalAdapter.findUserByEmail(email).then((res) => res?.user);
|
|
161
|
+
if (!user) if (!opts.disableSignUp) {
|
|
162
|
+
let newUser;
|
|
163
|
+
try {
|
|
164
|
+
newUser = await ctx.context.internalAdapter.createUser({
|
|
165
|
+
email,
|
|
166
|
+
emailVerified: true,
|
|
167
|
+
name: name || ""
|
|
168
|
+
}, { method: "magic-link" });
|
|
169
|
+
} catch (e) {
|
|
170
|
+
if (isAPIError(e) && e.body?.code) redirectWithError(e.body.code, e.body.message);
|
|
171
|
+
throw e;
|
|
172
|
+
}
|
|
173
|
+
isNewUser = true;
|
|
174
|
+
user = newUser;
|
|
175
|
+
if (!user) redirectWithError("failed_to_create_user");
|
|
176
|
+
} else redirectWithError("new_user_signup_disabled");
|
|
177
|
+
if (!user.emailVerified) {
|
|
178
|
+
const promotedUser = await revokeUnprovenAccountAccess(ctx, user.id);
|
|
179
|
+
if (!promotedUser) redirectWithError("user_not_found");
|
|
180
|
+
user = promotedUser;
|
|
181
|
+
}
|
|
182
|
+
const session = await ctx.context.internalAdapter.createSession(user.id);
|
|
183
|
+
if (!session) redirectWithError("failed_to_create_session");
|
|
184
|
+
await setSessionCookie(ctx, {
|
|
185
|
+
session,
|
|
186
|
+
user
|
|
187
|
+
});
|
|
188
|
+
if (!ctx.query.callbackURL) return ctx.json({
|
|
189
|
+
token: session.token,
|
|
190
|
+
user: parseUserOutput(ctx.context.options, user),
|
|
191
|
+
session: parseSessionOutput(ctx.context.options, session)
|
|
192
|
+
});
|
|
193
|
+
if (isNewUser) throw ctx.redirect(newUserCallbackURL);
|
|
194
|
+
throw ctx.redirect(callbackURL);
|
|
195
|
+
})
|
|
196
|
+
},
|
|
197
|
+
rateLimit: [{
|
|
198
|
+
pathMatcher(path) {
|
|
199
|
+
return path.startsWith("/sign-in/magic-link") || path.startsWith("/magic-link/verify");
|
|
200
|
+
},
|
|
201
|
+
window: opts.rateLimit?.window || 60,
|
|
202
|
+
max: opts.rateLimit?.max || 5
|
|
203
|
+
}],
|
|
204
|
+
options
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
//#endregion
|
|
208
|
+
export { magicLink };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { base64Url } from "@better-auth/utils/base64";
|
|
2
|
+
import { createHash } from "@better-auth/utils/hash";
|
|
3
|
+
//#region src/plugins/magic-link/utils.ts
|
|
4
|
+
const defaultKeyHasher = async (otp) => {
|
|
5
|
+
const hash = await createHash("SHA-256").digest(new TextEncoder().encode(otp));
|
|
6
|
+
return base64Url.encode(new Uint8Array(hash), { padding: false });
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { defaultKeyHasher };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MULTI_SESSION_ERROR_CODES } from "./error-codes.mjs";
|
|
2
|
+
import { MultiSessionConfig, multiSession } from "./index.mjs";
|
|
3
|
+
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/multi-session/client.d.ts
|
|
6
|
+
declare const multiSessionClient: () => {
|
|
7
|
+
id: "multi-session";
|
|
8
|
+
version: string;
|
|
9
|
+
$InferServerPlugin: ReturnType<typeof multiSession>;
|
|
10
|
+
atomListeners: {
|
|
11
|
+
matcher(path: string): path is "/multi-session/set-active";
|
|
12
|
+
signal: "$sessionSignal";
|
|
13
|
+
}[];
|
|
14
|
+
$ERROR_CODES: {
|
|
15
|
+
INVALID_SESSION_TOKEN: _$_better_auth_core_utils_error_codes0.RawError<"INVALID_SESSION_TOKEN">;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { multiSessionClient };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
2
|
+
import { MULTI_SESSION_ERROR_CODES } from "./error-codes.mjs";
|
|
3
|
+
//#region src/plugins/multi-session/client.ts
|
|
4
|
+
const multiSessionClient = () => {
|
|
5
|
+
return {
|
|
6
|
+
id: "multi-session",
|
|
7
|
+
version: PACKAGE_VERSION,
|
|
8
|
+
$InferServerPlugin: {},
|
|
9
|
+
atomListeners: [{
|
|
10
|
+
matcher(path) {
|
|
11
|
+
return path === "/multi-session/set-active";
|
|
12
|
+
},
|
|
13
|
+
signal: "$sessionSignal"
|
|
14
|
+
}],
|
|
15
|
+
$ERROR_CODES: MULTI_SESSION_ERROR_CODES
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { multiSessionClient };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/multi-session/error-codes.d.ts
|
|
4
|
+
declare const MULTI_SESSION_ERROR_CODES: {
|
|
5
|
+
INVALID_SESSION_TOKEN: _$_better_auth_core_utils_error_codes0.RawError<"INVALID_SESSION_TOKEN">;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MULTI_SESSION_ERROR_CODES };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
|
|
2
|
+
//#region src/plugins/multi-session/error-codes.ts
|
|
3
|
+
const MULTI_SESSION_ERROR_CODES = defineErrorCodes({ INVALID_SESSION_TOKEN: "Invalid session token" });
|
|
4
|
+
//#endregion
|
|
5
|
+
export { MULTI_SESSION_ERROR_CODES };
|