@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,368 @@
|
|
|
1
|
+
import { formCsrfMiddleware } from "../middlewares/origin-check.mjs";
|
|
2
|
+
import { parseUserOutput } from "../../db/schema.mjs";
|
|
3
|
+
import { setSessionCookie } from "../../cookies/index.mjs";
|
|
4
|
+
import { getAwaitableValue } from "../../context/helpers.mjs";
|
|
5
|
+
import { resolveOAuthAccountKeyForAPI, toOAuthProfileRecord } from "../../oauth2/account-key.mjs";
|
|
6
|
+
import { OAUTH_CALLBACK_ERROR_CODES, missingEmailLogMessage } from "../../oauth2/errors.mjs";
|
|
7
|
+
import { getOAuthCallbackPath } from "../../oauth2/utils.mjs";
|
|
8
|
+
import { handleOAuthUserInfo } from "../../oauth2/link-account.mjs";
|
|
9
|
+
import { generateIdTokenNonce, generateState } from "../../oauth2/state.mjs";
|
|
10
|
+
import { safeCloneRequest } from "../../utils/request.mjs";
|
|
11
|
+
import { createEmailVerificationToken } from "./email-verification.mjs";
|
|
12
|
+
import { APIError, BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
13
|
+
import { additionalAuthorizationParamsSchema, supportsIdTokenSignIn, verifyProviderIdToken } from "@better-auth/core/oauth2";
|
|
14
|
+
import { SocialProviderListEnum } from "@better-auth/core/social-providers";
|
|
15
|
+
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
16
|
+
import * as z from "zod";
|
|
17
|
+
//#region src/api/routes/sign-in.ts
|
|
18
|
+
const socialSignInBodySchema = z.object({
|
|
19
|
+
/**
|
|
20
|
+
* Callback URL to redirect to after the user
|
|
21
|
+
* has signed in.
|
|
22
|
+
*/
|
|
23
|
+
callbackURL: z.string().meta({ description: "Callback URL to redirect to after the user has signed in" }).optional(),
|
|
24
|
+
/**
|
|
25
|
+
* callback url to redirect if the user is newly registered.
|
|
26
|
+
*
|
|
27
|
+
* useful if you have different routes for existing users and new users
|
|
28
|
+
*/
|
|
29
|
+
newUserCallbackURL: z.string().optional(),
|
|
30
|
+
/**
|
|
31
|
+
* Callback url to redirect to if an error happens
|
|
32
|
+
*
|
|
33
|
+
* If it's initiated from the client sdk this defaults to
|
|
34
|
+
* the current url.
|
|
35
|
+
*/
|
|
36
|
+
errorCallbackURL: z.string().meta({ description: "Callback URL to redirect to if an error happens" }).optional(),
|
|
37
|
+
/**
|
|
38
|
+
* OAuth2 provider to use`
|
|
39
|
+
*/
|
|
40
|
+
provider: SocialProviderListEnum,
|
|
41
|
+
/**
|
|
42
|
+
* Disable automatic redirection to the provider
|
|
43
|
+
*
|
|
44
|
+
* This is useful if you want to handle the redirection
|
|
45
|
+
* yourself like in a popup or a different tab.
|
|
46
|
+
*/
|
|
47
|
+
disableRedirect: z.boolean().meta({ description: "Disable automatic redirection to the provider. Useful for handling the redirection yourself" }).optional(),
|
|
48
|
+
/**
|
|
49
|
+
* ID token from the provider
|
|
50
|
+
*
|
|
51
|
+
* This is used to sign in the user
|
|
52
|
+
* if the user is already signed in with the
|
|
53
|
+
* provider in the frontend.
|
|
54
|
+
*
|
|
55
|
+
* Only applicable if the provider supports
|
|
56
|
+
* it. Currently only `apple` and `google` is
|
|
57
|
+
* supported out of the box.
|
|
58
|
+
*/
|
|
59
|
+
idToken: z.optional(z.object({
|
|
60
|
+
/**
|
|
61
|
+
* ID token from the provider
|
|
62
|
+
*/
|
|
63
|
+
token: z.string().meta({ description: "ID token from the provider" }),
|
|
64
|
+
/**
|
|
65
|
+
* The nonce used to generate the token
|
|
66
|
+
*/
|
|
67
|
+
nonce: z.string().meta({ description: "Nonce used to generate the token" }).optional(),
|
|
68
|
+
/**
|
|
69
|
+
* Access token from the provider
|
|
70
|
+
*/
|
|
71
|
+
accessToken: z.string().meta({ description: "Access token from the provider" }).optional(),
|
|
72
|
+
/**
|
|
73
|
+
* Refresh token from the provider
|
|
74
|
+
*/
|
|
75
|
+
refreshToken: z.string().meta({ description: "Refresh token from the provider" }).optional(),
|
|
76
|
+
/**
|
|
77
|
+
* Expiry date of the token
|
|
78
|
+
*/
|
|
79
|
+
expiresAt: z.number().meta({ description: "Expiry date of the token" }).optional(),
|
|
80
|
+
/**
|
|
81
|
+
* The user object from the provider.
|
|
82
|
+
* This is only available for some providers like Apple.
|
|
83
|
+
*/
|
|
84
|
+
user: z.object({
|
|
85
|
+
name: z.object({
|
|
86
|
+
firstName: z.string().optional(),
|
|
87
|
+
lastName: z.string().optional()
|
|
88
|
+
}).optional(),
|
|
89
|
+
email: z.string().optional()
|
|
90
|
+
}).meta({ description: "The user object from the provider. Only available for some providers like Apple." }).optional()
|
|
91
|
+
})),
|
|
92
|
+
scopes: z.array(z.string()).meta({ description: "Array of scopes to request from the provider. This will override the default scopes passed." }).optional(),
|
|
93
|
+
/**
|
|
94
|
+
* Explicitly request sign-up
|
|
95
|
+
*
|
|
96
|
+
* Should be used to allow sign up when
|
|
97
|
+
* disableImplicitSignUp for this provider is
|
|
98
|
+
* true
|
|
99
|
+
*/
|
|
100
|
+
requestSignUp: z.boolean().meta({ description: "Explicitly request sign-up. Useful when disableImplicitSignUp is true for this provider" }).optional(),
|
|
101
|
+
/**
|
|
102
|
+
* The login hint to use for the authorization code request
|
|
103
|
+
*/
|
|
104
|
+
loginHint: z.string().meta({ description: "The login hint to use for the authorization code request" }).optional(),
|
|
105
|
+
/**
|
|
106
|
+
* Extra query parameters to append to the provider authorization URL.
|
|
107
|
+
* Reserved OAuth keys (state, client_id, redirect_uri, response_type,
|
|
108
|
+
* code_challenge, code_challenge_method, nonce, scope) are rejected.
|
|
109
|
+
*/
|
|
110
|
+
additionalParams: additionalAuthorizationParamsSchema,
|
|
111
|
+
/**
|
|
112
|
+
* Additional data to be passed through the OAuth flow
|
|
113
|
+
*/
|
|
114
|
+
additionalData: z.record(z.string(), z.any()).optional().meta({ description: "Additional data to be passed through the OAuth flow" })
|
|
115
|
+
});
|
|
116
|
+
const signInSocial = () => createAuthEndpoint("/sign-in/social", {
|
|
117
|
+
method: "POST",
|
|
118
|
+
operationId: "socialSignIn",
|
|
119
|
+
body: socialSignInBodySchema,
|
|
120
|
+
metadata: {
|
|
121
|
+
$Infer: {
|
|
122
|
+
body: {},
|
|
123
|
+
returned: {}
|
|
124
|
+
},
|
|
125
|
+
openapi: {
|
|
126
|
+
description: "Sign in with a social provider",
|
|
127
|
+
operationId: "socialSignIn",
|
|
128
|
+
responses: { "200": {
|
|
129
|
+
description: "Success - Returns session details (idToken branch) or an authorize URL (redirect branch)",
|
|
130
|
+
content: { "application/json": { schema: {
|
|
131
|
+
type: "object",
|
|
132
|
+
description: "Returns session details when idToken is provided, or an authorize URL otherwise",
|
|
133
|
+
properties: {
|
|
134
|
+
token: { type: "string" },
|
|
135
|
+
user: {
|
|
136
|
+
type: "object",
|
|
137
|
+
$ref: "#/components/schemas/User"
|
|
138
|
+
},
|
|
139
|
+
url: { type: "string" },
|
|
140
|
+
redirect: { type: "boolean" }
|
|
141
|
+
},
|
|
142
|
+
required: ["redirect"]
|
|
143
|
+
} } }
|
|
144
|
+
} }
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}, async (c) => {
|
|
148
|
+
const provider = await getAwaitableValue(c.context.socialProviders, { value: c.body.provider });
|
|
149
|
+
if (!provider) {
|
|
150
|
+
c.context.logger.error("Provider not found. Make sure to add the provider in your auth config", { provider: c.body.provider });
|
|
151
|
+
throw APIError.from("NOT_FOUND", BASE_ERROR_CODES.PROVIDER_NOT_FOUND);
|
|
152
|
+
}
|
|
153
|
+
if (c.body.idToken) {
|
|
154
|
+
if (!supportsIdTokenSignIn(provider)) {
|
|
155
|
+
c.context.logger.error("Provider does not support id token verification", { provider: c.body.provider });
|
|
156
|
+
throw APIError.from("NOT_FOUND", BASE_ERROR_CODES.ID_TOKEN_NOT_SUPPORTED);
|
|
157
|
+
}
|
|
158
|
+
const { token, nonce } = c.body.idToken;
|
|
159
|
+
if (!await verifyProviderIdToken(provider, token, nonce, c)) {
|
|
160
|
+
c.context.logger.warn("Invalid id token", { provider: c.body.provider });
|
|
161
|
+
throw APIError.from("UNAUTHORIZED", BASE_ERROR_CODES.INVALID_TOKEN);
|
|
162
|
+
}
|
|
163
|
+
const oauthTokens = {
|
|
164
|
+
idToken: token,
|
|
165
|
+
accessToken: c.body.idToken.accessToken,
|
|
166
|
+
refreshToken: c.body.idToken.refreshToken,
|
|
167
|
+
user: c.body.idToken.user
|
|
168
|
+
};
|
|
169
|
+
const userInfo = await provider.getUserInfo(oauthTokens);
|
|
170
|
+
if (!userInfo || !userInfo?.user) {
|
|
171
|
+
c.context.logger.error("Failed to get user info", { provider: c.body.provider });
|
|
172
|
+
throw APIError.from("UNAUTHORIZED", BASE_ERROR_CODES.FAILED_TO_GET_USER_INFO);
|
|
173
|
+
}
|
|
174
|
+
if (!userInfo.user.email) {
|
|
175
|
+
c.context.logger.error(missingEmailLogMessage(c.body.provider, { source: "id_token" }), { provider: c.body.provider });
|
|
176
|
+
throw APIError.from("UNAUTHORIZED", BASE_ERROR_CODES.USER_EMAIL_NOT_FOUND);
|
|
177
|
+
}
|
|
178
|
+
const accountKey = await resolveOAuthAccountKeyForAPI(provider, oauthTokens, userInfo.data);
|
|
179
|
+
const providerProfile = toOAuthProfileRecord(userInfo.data);
|
|
180
|
+
const data = await handleOAuthUserInfo(c, {
|
|
181
|
+
userInfo: {
|
|
182
|
+
...userInfo.user,
|
|
183
|
+
email: userInfo.user.email,
|
|
184
|
+
id: accountKey.accountId,
|
|
185
|
+
name: userInfo.user.name || "",
|
|
186
|
+
image: userInfo.user.image,
|
|
187
|
+
emailVerified: userInfo.user.emailVerified || false
|
|
188
|
+
},
|
|
189
|
+
account: {
|
|
190
|
+
...accountKey,
|
|
191
|
+
accessToken: c.body.idToken.accessToken,
|
|
192
|
+
idToken: token
|
|
193
|
+
},
|
|
194
|
+
callbackURL: c.body.callbackURL,
|
|
195
|
+
disableSignUp: provider.disableImplicitSignUp && !c.body.requestSignUp || provider.disableSignUp,
|
|
196
|
+
source: {
|
|
197
|
+
method: "oauth",
|
|
198
|
+
oauth: {
|
|
199
|
+
providerId: provider.id,
|
|
200
|
+
profile: providerProfile
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
if (data.error) {
|
|
205
|
+
if (data.error === OAUTH_CALLBACK_ERROR_CODES.EMAIL_NOT_VERIFIED) throw APIError.from("FORBIDDEN", BASE_ERROR_CODES.EMAIL_NOT_VERIFIED);
|
|
206
|
+
throw APIError.from("UNAUTHORIZED", {
|
|
207
|
+
message: data.error,
|
|
208
|
+
code: "OAUTH_LINK_ERROR"
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
await setSessionCookie(c, data.data);
|
|
212
|
+
return c.json({
|
|
213
|
+
redirect: false,
|
|
214
|
+
token: data.data.session.token,
|
|
215
|
+
url: void 0,
|
|
216
|
+
user: parseUserOutput(c.context.options, data.data.user)
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
const idTokenNonce = generateIdTokenNonce(provider);
|
|
220
|
+
const { codeVerifier, state } = await generateState(c, {
|
|
221
|
+
additionalData: c.body.additionalData,
|
|
222
|
+
idTokenNonce
|
|
223
|
+
});
|
|
224
|
+
const url = await provider.createAuthorizationURL({
|
|
225
|
+
state,
|
|
226
|
+
codeVerifier,
|
|
227
|
+
idTokenNonce,
|
|
228
|
+
redirectURI: `${c.context.baseURL}${getOAuthCallbackPath(provider)}`,
|
|
229
|
+
scopes: c.body.scopes,
|
|
230
|
+
loginHint: c.body.loginHint,
|
|
231
|
+
additionalParams: c.body.additionalParams
|
|
232
|
+
});
|
|
233
|
+
if (!c.body.disableRedirect) c.setHeader("Location", url.toString());
|
|
234
|
+
return c.json({
|
|
235
|
+
url: url.toString(),
|
|
236
|
+
redirect: !c.body.disableRedirect
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
const signInEmail = () => createAuthEndpoint("/sign-in/email", {
|
|
240
|
+
method: "POST",
|
|
241
|
+
operationId: "signInEmail",
|
|
242
|
+
use: [formCsrfMiddleware],
|
|
243
|
+
cloneRequest: true,
|
|
244
|
+
body: z.object({
|
|
245
|
+
/**
|
|
246
|
+
* Email of the user
|
|
247
|
+
*/
|
|
248
|
+
email: z.string().meta({ description: "Email of the user" }),
|
|
249
|
+
/**
|
|
250
|
+
* Password of the user
|
|
251
|
+
*/
|
|
252
|
+
password: z.string().meta({ description: "Password of the user" }),
|
|
253
|
+
/**
|
|
254
|
+
* Callback URL to use as a redirect for email
|
|
255
|
+
* verification and for possible redirects
|
|
256
|
+
*/
|
|
257
|
+
callbackURL: z.string().meta({ description: "Callback URL to use as a redirect for email verification" }).optional(),
|
|
258
|
+
/**
|
|
259
|
+
* If this is false, the session will not be remembered
|
|
260
|
+
* @default true
|
|
261
|
+
*/
|
|
262
|
+
rememberMe: z.boolean().meta({ description: "If this is false, the session will not be remembered. Default is `true`." }).default(true).optional()
|
|
263
|
+
}),
|
|
264
|
+
metadata: {
|
|
265
|
+
allowedMediaTypes: ["application/x-www-form-urlencoded", "application/json"],
|
|
266
|
+
$Infer: {
|
|
267
|
+
body: {},
|
|
268
|
+
returned: {}
|
|
269
|
+
},
|
|
270
|
+
openapi: {
|
|
271
|
+
operationId: "signInEmail",
|
|
272
|
+
description: "Sign in with email and password",
|
|
273
|
+
responses: { "200": {
|
|
274
|
+
description: "Success - Returns either session details or redirect URL",
|
|
275
|
+
content: { "application/json": { schema: {
|
|
276
|
+
type: "object",
|
|
277
|
+
description: "Session response when idToken is provided",
|
|
278
|
+
properties: {
|
|
279
|
+
redirect: {
|
|
280
|
+
type: "boolean",
|
|
281
|
+
enum: [false]
|
|
282
|
+
},
|
|
283
|
+
token: {
|
|
284
|
+
type: "string",
|
|
285
|
+
description: "Session token"
|
|
286
|
+
},
|
|
287
|
+
url: {
|
|
288
|
+
type: "string",
|
|
289
|
+
nullable: true
|
|
290
|
+
},
|
|
291
|
+
user: {
|
|
292
|
+
type: "object",
|
|
293
|
+
$ref: "#/components/schemas/User"
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
required: [
|
|
297
|
+
"redirect",
|
|
298
|
+
"token",
|
|
299
|
+
"user"
|
|
300
|
+
]
|
|
301
|
+
} } }
|
|
302
|
+
} }
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}, async (ctx) => {
|
|
306
|
+
if (!ctx.context.options?.emailAndPassword?.enabled) {
|
|
307
|
+
ctx.context.logger.error("Email and password is not enabled. Make sure to enable it in the options on you `auth.ts` file. Check `https://better-auth.com/docs/authentication/email-password` for more!");
|
|
308
|
+
throw APIError.from("BAD_REQUEST", {
|
|
309
|
+
code: "EMAIL_PASSWORD_DISABLED",
|
|
310
|
+
message: "Email and password is not enabled"
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
const { email, password } = ctx.body;
|
|
314
|
+
if (!z.email().safeParse(email).success) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.INVALID_EMAIL);
|
|
315
|
+
const userRecord = await ctx.context.internalAdapter.findUserByEmail(email.toLowerCase(), { includeAccounts: true });
|
|
316
|
+
const credentialAccount = userRecord?.accounts.find((account) => account.providerId === "credential" && account.accountId === userRecord.user.id);
|
|
317
|
+
if (!userRecord || !credentialAccount) {
|
|
318
|
+
await ctx.context.password.hash(password);
|
|
319
|
+
ctx.context.logger.warn("User not found");
|
|
320
|
+
throw APIError.from("UNAUTHORIZED", BASE_ERROR_CODES.INVALID_EMAIL_OR_PASSWORD);
|
|
321
|
+
}
|
|
322
|
+
const user = userRecord.user;
|
|
323
|
+
const currentPassword = credentialAccount.password;
|
|
324
|
+
if (!currentPassword) {
|
|
325
|
+
await ctx.context.password.hash(password);
|
|
326
|
+
ctx.context.logger.warn("Password not found");
|
|
327
|
+
throw APIError.from("UNAUTHORIZED", BASE_ERROR_CODES.INVALID_EMAIL_OR_PASSWORD);
|
|
328
|
+
}
|
|
329
|
+
if (!await ctx.context.password.verify({
|
|
330
|
+
hash: currentPassword,
|
|
331
|
+
password
|
|
332
|
+
})) {
|
|
333
|
+
ctx.context.logger.warn("Invalid password");
|
|
334
|
+
throw APIError.from("UNAUTHORIZED", BASE_ERROR_CODES.INVALID_EMAIL_OR_PASSWORD);
|
|
335
|
+
}
|
|
336
|
+
if (ctx.context.options?.emailAndPassword?.requireEmailVerification && !user.emailVerified) {
|
|
337
|
+
if (!ctx.context.options?.emailVerification?.sendVerificationEmail) throw APIError.from("FORBIDDEN", BASE_ERROR_CODES.EMAIL_NOT_VERIFIED);
|
|
338
|
+
if (ctx.context.options?.emailVerification?.sendOnSignIn) {
|
|
339
|
+
const token = await createEmailVerificationToken(ctx.context.secret, user.email, void 0, ctx.context.options.emailVerification?.expiresIn);
|
|
340
|
+
const callbackURL = ctx.body.callbackURL ? encodeURIComponent(ctx.body.callbackURL) : encodeURIComponent("/");
|
|
341
|
+
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${callbackURL}`;
|
|
342
|
+
await ctx.context.runInBackgroundOrAwait(ctx.context.options.emailVerification.sendVerificationEmail({
|
|
343
|
+
user,
|
|
344
|
+
url,
|
|
345
|
+
token
|
|
346
|
+
}, safeCloneRequest(ctx.request)));
|
|
347
|
+
}
|
|
348
|
+
throw APIError.from("FORBIDDEN", BASE_ERROR_CODES.EMAIL_NOT_VERIFIED);
|
|
349
|
+
}
|
|
350
|
+
const session = await ctx.context.internalAdapter.createSession(user.id, ctx.body.rememberMe === false);
|
|
351
|
+
if (!session) {
|
|
352
|
+
ctx.context.logger.error("Failed to create session");
|
|
353
|
+
throw APIError.from("UNAUTHORIZED", BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION);
|
|
354
|
+
}
|
|
355
|
+
await setSessionCookie(ctx, {
|
|
356
|
+
session,
|
|
357
|
+
user
|
|
358
|
+
}, ctx.body.rememberMe === false);
|
|
359
|
+
if (ctx.body.callbackURL) ctx.setHeader("Location", ctx.body.callbackURL);
|
|
360
|
+
return ctx.json({
|
|
361
|
+
redirect: !!ctx.body.callbackURL,
|
|
362
|
+
token: session.token,
|
|
363
|
+
url: ctx.body.callbackURL,
|
|
364
|
+
user: parseUserOutput(ctx.context.options, user)
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
//#endregion
|
|
368
|
+
export { signInEmail, signInSocial };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as _$better_call0 from "better-call";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/api/routes/sign-out.d.ts
|
|
5
|
+
declare const signOut: _$better_call0.StrictEndpoint<"/sign-out", {
|
|
6
|
+
method: "POST";
|
|
7
|
+
body: z.ZodOptional<z.ZodObject<{
|
|
8
|
+
callbackURL: z.ZodOptional<z.ZodString>;
|
|
9
|
+
disableRedirect: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
state: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, z.core.$strip>>;
|
|
12
|
+
operationId: string;
|
|
13
|
+
requireHeaders: true;
|
|
14
|
+
metadata: {
|
|
15
|
+
openapi: {
|
|
16
|
+
operationId: string;
|
|
17
|
+
description: string;
|
|
18
|
+
responses: {
|
|
19
|
+
"200": {
|
|
20
|
+
description: string;
|
|
21
|
+
content: {
|
|
22
|
+
"application/json": {
|
|
23
|
+
schema: {
|
|
24
|
+
type: "object";
|
|
25
|
+
properties: {
|
|
26
|
+
success: {
|
|
27
|
+
type: string;
|
|
28
|
+
};
|
|
29
|
+
url: {
|
|
30
|
+
type: string;
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
redirect: {
|
|
34
|
+
type: string;
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}, {
|
|
46
|
+
success: boolean;
|
|
47
|
+
url: string | undefined;
|
|
48
|
+
redirect: boolean | undefined;
|
|
49
|
+
}>;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { signOut };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { deleteSessionCookie } from "../../cookies/index.mjs";
|
|
2
|
+
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/api/routes/sign-out.ts
|
|
5
|
+
const signOutBodySchema = z.object({
|
|
6
|
+
callbackURL: z.string().meta({ description: "The URL to redirect to after provider logout" }).optional(),
|
|
7
|
+
disableRedirect: z.boolean().meta({ description: "Return the provider logout URL without redirecting" }).optional(),
|
|
8
|
+
state: z.string().meta({ description: "State to pass to the provider logout endpoint" }).optional()
|
|
9
|
+
}).optional();
|
|
10
|
+
const signOutResponse = (providerLogout) => ({
|
|
11
|
+
success: true,
|
|
12
|
+
url: providerLogout?.url,
|
|
13
|
+
redirect: providerLogout?.redirect
|
|
14
|
+
});
|
|
15
|
+
const signOut = createAuthEndpoint("/sign-out", {
|
|
16
|
+
method: "POST",
|
|
17
|
+
body: signOutBodySchema,
|
|
18
|
+
operationId: "signOut",
|
|
19
|
+
requireHeaders: true,
|
|
20
|
+
metadata: { openapi: {
|
|
21
|
+
operationId: "signOut",
|
|
22
|
+
description: "Sign out the current user",
|
|
23
|
+
responses: { "200": {
|
|
24
|
+
description: "Success",
|
|
25
|
+
content: { "application/json": { schema: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
success: { type: "boolean" },
|
|
29
|
+
url: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Provider logout URL when RP-initiated logout is available"
|
|
32
|
+
},
|
|
33
|
+
redirect: {
|
|
34
|
+
type: "boolean",
|
|
35
|
+
description: "Whether the client should redirect to the provider logout URL"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} } }
|
|
39
|
+
} }
|
|
40
|
+
} }
|
|
41
|
+
}, async (ctx) => {
|
|
42
|
+
const sessionCookieToken = await ctx.getSignedCookie(ctx.context.authCookies.sessionToken.name, ctx.context.secret);
|
|
43
|
+
let currentSession = null;
|
|
44
|
+
if (sessionCookieToken) try {
|
|
45
|
+
currentSession = await ctx.context.internalAdapter.findSession(sessionCookieToken);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
ctx.context.logger.error("Failed to read session from database", e);
|
|
48
|
+
}
|
|
49
|
+
if (sessionCookieToken) try {
|
|
50
|
+
await ctx.context.internalAdapter.deleteSession(sessionCookieToken);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
ctx.context.logger.error("Failed to delete session from database", e);
|
|
53
|
+
}
|
|
54
|
+
deleteSessionCookie(ctx);
|
|
55
|
+
const providerLogoutResult = await (async () => {
|
|
56
|
+
try {
|
|
57
|
+
if (!currentSession) return null;
|
|
58
|
+
const accounts = await ctx.context.internalAdapter.findAccounts(currentSession.user.id);
|
|
59
|
+
const providersById = new Map(ctx.context.socialProviders.map((provider) => [provider.id, provider]));
|
|
60
|
+
const logoutAccounts = accounts.filter((account) => Boolean(providersById.get(account.providerId)?.createEndSessionURL)).sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
61
|
+
if (logoutAccounts.length === 0) return null;
|
|
62
|
+
const seenProviderIds = /* @__PURE__ */ new Set();
|
|
63
|
+
const postLogoutRedirectURI = ctx.body?.callbackURL ? new URL(ctx.body.callbackURL, ctx.context.baseURL).toString() : void 0;
|
|
64
|
+
for (const account of logoutAccounts) {
|
|
65
|
+
if (seenProviderIds.has(account.providerId)) continue;
|
|
66
|
+
seenProviderIds.add(account.providerId);
|
|
67
|
+
const provider = providersById.get(account.providerId);
|
|
68
|
+
try {
|
|
69
|
+
const url = await provider?.createEndSessionURL?.({
|
|
70
|
+
idToken: account.idToken,
|
|
71
|
+
postLogoutRedirectURI,
|
|
72
|
+
state: ctx.body?.state
|
|
73
|
+
});
|
|
74
|
+
if (url) return url.toString();
|
|
75
|
+
} catch (e) {
|
|
76
|
+
ctx.context.logger.error(`Failed to create logout URL for provider "${account.providerId}"`, e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
} catch (e) {
|
|
81
|
+
ctx.context.logger.error("Failed to create provider logout URL", e);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
if (providerLogoutResult) {
|
|
86
|
+
const shouldRedirect = !ctx.body?.disableRedirect;
|
|
87
|
+
if (shouldRedirect) ctx.setHeader("Location", providerLogoutResult);
|
|
88
|
+
return ctx.json(signOutResponse({
|
|
89
|
+
url: providerLogoutResult,
|
|
90
|
+
redirect: shouldRedirect
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
return ctx.json(signOutResponse());
|
|
94
|
+
});
|
|
95
|
+
//#endregion
|
|
96
|
+
export { signOut };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { AdditionalUserFieldsInput, User } from "../../types/models.mjs";
|
|
2
|
+
import { BetterAuthOptions } from "@better-auth/core";
|
|
3
|
+
import * as _$better_call0 from "better-call";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/api/routes/sign-up.d.ts
|
|
7
|
+
declare const signUpEmail: <O extends BetterAuthOptions>() => _$better_call0.StrictEndpoint<"/sign-up/email", {
|
|
8
|
+
method: "POST";
|
|
9
|
+
operationId: string;
|
|
10
|
+
use: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, (inputContext: _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>) => Promise<void>>[];
|
|
11
|
+
body: z.ZodIntersection<z.ZodObject<{
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
email: z.ZodEmail;
|
|
14
|
+
password: z.ZodString;
|
|
15
|
+
image: z.ZodOptional<z.ZodString>;
|
|
16
|
+
callbackURL: z.ZodOptional<z.ZodString>;
|
|
17
|
+
rememberMe: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
}, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
19
|
+
cloneRequest: true;
|
|
20
|
+
metadata: {
|
|
21
|
+
allowedMediaTypes: string[];
|
|
22
|
+
$Infer: {
|
|
23
|
+
body: {
|
|
24
|
+
name: string;
|
|
25
|
+
email: string;
|
|
26
|
+
password: string;
|
|
27
|
+
image?: string | undefined;
|
|
28
|
+
callbackURL?: string | undefined;
|
|
29
|
+
rememberMe?: boolean | undefined;
|
|
30
|
+
} & AdditionalUserFieldsInput<O>;
|
|
31
|
+
returned: {
|
|
32
|
+
token: string | null;
|
|
33
|
+
user: User<O["user"], O["plugins"]>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
openapi: {
|
|
37
|
+
operationId: string;
|
|
38
|
+
description: string;
|
|
39
|
+
requestBody: {
|
|
40
|
+
content: {
|
|
41
|
+
"application/json": {
|
|
42
|
+
schema: {
|
|
43
|
+
type: "object";
|
|
44
|
+
properties: {
|
|
45
|
+
name: {
|
|
46
|
+
type: string;
|
|
47
|
+
description: string;
|
|
48
|
+
};
|
|
49
|
+
email: {
|
|
50
|
+
type: string;
|
|
51
|
+
description: string;
|
|
52
|
+
};
|
|
53
|
+
password: {
|
|
54
|
+
type: string;
|
|
55
|
+
description: string;
|
|
56
|
+
};
|
|
57
|
+
image: {
|
|
58
|
+
type: string;
|
|
59
|
+
description: string;
|
|
60
|
+
};
|
|
61
|
+
callbackURL: {
|
|
62
|
+
type: string;
|
|
63
|
+
description: string;
|
|
64
|
+
};
|
|
65
|
+
rememberMe: {
|
|
66
|
+
type: string;
|
|
67
|
+
description: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
required: string[];
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
responses: {
|
|
76
|
+
"200": {
|
|
77
|
+
description: string;
|
|
78
|
+
content: {
|
|
79
|
+
"application/json": {
|
|
80
|
+
schema: {
|
|
81
|
+
type: "object";
|
|
82
|
+
properties: {
|
|
83
|
+
token: {
|
|
84
|
+
type: string;
|
|
85
|
+
nullable: boolean;
|
|
86
|
+
description: string;
|
|
87
|
+
};
|
|
88
|
+
user: {
|
|
89
|
+
type: string;
|
|
90
|
+
properties: {
|
|
91
|
+
id: {
|
|
92
|
+
type: string;
|
|
93
|
+
description: string;
|
|
94
|
+
};
|
|
95
|
+
email: {
|
|
96
|
+
type: string;
|
|
97
|
+
format: string;
|
|
98
|
+
description: string;
|
|
99
|
+
};
|
|
100
|
+
name: {
|
|
101
|
+
type: string;
|
|
102
|
+
description: string;
|
|
103
|
+
};
|
|
104
|
+
image: {
|
|
105
|
+
type: string;
|
|
106
|
+
format: string;
|
|
107
|
+
nullable: boolean;
|
|
108
|
+
description: string;
|
|
109
|
+
};
|
|
110
|
+
emailVerified: {
|
|
111
|
+
type: string;
|
|
112
|
+
description: string;
|
|
113
|
+
};
|
|
114
|
+
createdAt: {
|
|
115
|
+
type: string;
|
|
116
|
+
format: string;
|
|
117
|
+
description: string;
|
|
118
|
+
};
|
|
119
|
+
updatedAt: {
|
|
120
|
+
type: string;
|
|
121
|
+
format: string;
|
|
122
|
+
description: string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
required: string[];
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
required: string[];
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
"422": {
|
|
134
|
+
description: string;
|
|
135
|
+
content: {
|
|
136
|
+
"application/json": {
|
|
137
|
+
schema: {
|
|
138
|
+
type: "object";
|
|
139
|
+
properties: {
|
|
140
|
+
message: {
|
|
141
|
+
type: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
}, {
|
|
152
|
+
token: null;
|
|
153
|
+
user: User<O["user"], O["plugins"]>;
|
|
154
|
+
} | {
|
|
155
|
+
token: string;
|
|
156
|
+
user: User<O["user"], O["plugins"]>;
|
|
157
|
+
}>;
|
|
158
|
+
//#endregion
|
|
159
|
+
export { signUpEmail };
|