@entro314labs/entro-auth 0.0.0-stage → 1.8.0-beta.11
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/dist/_virtual/_rolldown/runtime.mjs +26 -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 +19 -0
- package/dist/adapters/index.mjs +8 -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/api/dispatch.d.mts +31 -0
- package/dist/api/dispatch.mjs +318 -0
- package/dist/api/index.d.mts +4117 -0
- package/dist/api/index.mjs +227 -0
- package/dist/api/middlewares/authorization.d.mts +70 -0
- package/dist/api/middlewares/authorization.mjs +78 -0
- package/dist/api/middlewares/index.d.mts +3 -0
- package/dist/api/middlewares/origin-check.d.mts +12 -0
- package/dist/api/middlewares/origin-check.mjs +154 -0
- package/dist/api/rate-limiter/index.mjs +322 -0
- package/dist/api/routes/account.d.mts +407 -0
- package/dist/api/routes/account.mjs +642 -0
- package/dist/api/routes/callback.d.mts +27 -0
- package/dist/api/routes/callback.mjs +184 -0
- package/dist/api/routes/email-verification.d.mts +153 -0
- package/dist/api/routes/email-verification.mjs +315 -0
- package/dist/api/routes/error.d.mts +22 -0
- package/dist/api/routes/error.mjs +386 -0
- package/dist/api/routes/id-token-nonce.d.mts +83 -0
- package/dist/api/routes/id-token-nonce.mjs +79 -0
- package/dist/api/routes/index.d.mts +14 -0
- package/dist/api/routes/ok.d.mts +30 -0
- package/dist/api/routes/ok.mjs +26 -0
- package/dist/api/routes/password.d.mts +177 -0
- package/dist/api/routes/password.mjs +198 -0
- package/dist/api/routes/session.d.mts +446 -0
- package/dist/api/routes/session.mjs +488 -0
- package/dist/api/routes/sign-in.d.mts +182 -0
- package/dist/api/routes/sign-in.mjs +374 -0
- package/dist/api/routes/sign-out.d.mts +46 -0
- package/dist/api/routes/sign-out.mjs +101 -0
- package/dist/api/routes/sign-up.d.mts +155 -0
- package/dist/api/routes/sign-up.mjs +279 -0
- package/dist/api/routes/update-session.d.mts +70 -0
- package/dist/api/routes/update-session.mjs +56 -0
- package/dist/api/routes/update-user.d.mts +424 -0
- package/dist/api/routes/update-user.mjs +524 -0
- package/dist/api/state/oauth.d.mts +48 -0
- package/dist/api/state/oauth.mjs +38 -0
- package/dist/api/state/should-session-refresh.d.mts +10 -0
- package/dist/api/state/should-session-refresh.mjs +12 -0
- package/dist/api/to-auth-endpoints.mjs +59 -0
- package/dist/auth/base.mjs +60 -0
- package/dist/auth/full.d.mts +25 -0
- package/dist/auth/full.mjs +28 -0
- package/dist/auth/minimal.d.mts +8 -0
- package/dist/auth/minimal.mjs +10 -0
- package/dist/auth/trusted-origins.mjs +130 -0
- package/dist/client/broadcast-channel.d.mts +16 -0
- package/dist/client/broadcast-channel.mjs +44 -0
- package/dist/client/config.d.mts +84 -0
- package/dist/client/config.mjs +111 -0
- package/dist/client/equality.d.mts +15 -0
- package/dist/client/equality.mjs +41 -0
- package/dist/client/fetch-plugins.mjs +16 -0
- package/dist/client/focus-manager.d.mts +7 -0
- package/dist/client/focus-manager.mjs +30 -0
- package/dist/client/index.d.mts +35 -0
- package/dist/client/index.mjs +21 -0
- package/dist/client/lynx/index.d.mts +40 -0
- package/dist/client/lynx/index.mjs +22 -0
- package/dist/client/lynx/lynx-store.d.mts +43 -0
- package/dist/client/lynx/lynx-store.mjs +43 -0
- package/dist/client/online-manager.d.mts +8 -0
- package/dist/client/online-manager.mjs +33 -0
- package/dist/client/parser.d.mts +12 -0
- package/dist/client/parser.mjs +59 -0
- package/dist/client/path-to-object.d.mts +110 -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 +12 -0
- package/dist/client/plugins/infer-plugin.mjs +10 -0
- package/dist/client/proxy.mjs +70 -0
- package/dist/client/query-atom.mjs +12 -0
- package/dist/client/query.d.mts +19 -0
- package/dist/client/query.mjs +133 -0
- package/dist/client/react/index.d.mts +41 -0
- package/dist/client/react/index.mjs +22 -0
- package/dist/client/react/react-store.d.mts +43 -0
- package/dist/client/react/react-store.mjs +44 -0
- package/dist/client/session-atom.d.mts +9 -0
- package/dist/client/session-atom.mjs +179 -0
- package/dist/client/session-refresh.d.mts +16 -0
- package/dist/client/session-refresh.mjs +131 -0
- package/dist/client/solid/index.d.mts +41 -0
- package/dist/client/solid/index.mjs +22 -0
- package/dist/client/solid/solid-store.mjs +20 -0
- package/dist/client/svelte/index.d.mts +41 -0
- package/dist/client/svelte/index.mjs +18 -0
- package/dist/client/types.d.mts +49 -0
- package/dist/client/vanilla.d.mts +39 -0
- package/dist/client/vanilla.mjs +18 -0
- package/dist/client/vue/index.d.mts +64 -0
- package/dist/client/vue/index.mjs +60 -0
- package/dist/client/vue/vue-store.mjs +22 -0
- package/dist/context/create-context.mjs +229 -0
- package/dist/context/helpers.mjs +159 -0
- package/dist/context/init-minimal.mjs +15 -0
- package/dist/context/init.mjs +16 -0
- package/dist/context/secret-utils.mjs +52 -0
- package/dist/context/store-capabilities.mjs +11 -0
- package/dist/cookies/cache.mjs +33 -0
- package/dist/cookies/cookie-utils.d.mts +70 -0
- package/dist/cookies/cookie-utils.mjs +200 -0
- package/dist/cookies/index.d.mts +121 -0
- package/dist/cookies/index.mjs +356 -0
- package/dist/cookies/jwt.mjs +44 -0
- package/dist/cookies/session-store.d.mts +31 -0
- package/dist/cookies/session-store.mjs +183 -0
- package/dist/crypto/buffer.d.mts +4 -0
- package/dist/crypto/buffer.mjs +15 -0
- package/dist/crypto/index.d.mts +24 -0
- package/dist/crypto/index.mjs +70 -0
- package/dist/crypto/jwt.d.mts +5 -0
- package/dist/crypto/jwt.mjs +141 -0
- package/dist/crypto/password.d.mts +7 -0
- package/dist/crypto/password.mjs +13 -0
- package/dist/crypto/purpose.d.mts +12 -0
- package/dist/crypto/purpose.mjs +27 -0
- package/dist/crypto/random.d.mts +1 -0
- package/dist/crypto/random.mjs +4 -0
- package/dist/db/adapter-base.d.mts +3 -0
- package/dist/db/adapter-base.mjs +24 -0
- package/dist/db/adapter-kysely.d.mts +3 -0
- package/dist/db/adapter-kysely.mjs +16 -0
- package/dist/db/field-converter.d.mts +3 -0
- package/dist/db/field-converter.mjs +18 -0
- package/dist/db/field.d.mts +38 -0
- package/dist/db/get-migration.d.mts +50 -0
- package/dist/db/get-migration.mjs +685 -0
- package/dist/db/get-schema.d.mts +9 -0
- package/dist/db/get-schema.mjs +54 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +34 -0
- package/dist/db/internal-adapter.d.mts +10 -0
- package/dist/db/internal-adapter.mjs +1083 -0
- package/dist/db/revoke-unproven-account-access.d.mts +18 -0
- package/dist/db/revoke-unproven-account-access.mjs +57 -0
- package/dist/db/schema.d.mts +59 -0
- package/dist/db/schema.mjs +172 -0
- package/dist/db/to-zod.d.mts +31 -0
- package/dist/db/to-zod.mjs +32 -0
- package/dist/db/verification-token-storage.mjs +24 -0
- package/dist/db/with-hooks.d.mts +33 -0
- package/dist/db/with-hooks.mjs +248 -0
- package/dist/index.d.mts +30 -0
- package/dist/index.mjs +16 -0
- package/dist/integrations/cookie-plugin-guard.mjs +17 -0
- package/dist/integrations/next-js.d.mts +23 -0
- package/dist/integrations/next-js.mjs +104 -0
- package/dist/integrations/node.d.mts +7 -0
- package/dist/integrations/node.mjs +14 -0
- package/dist/integrations/solid-start.d.mts +19 -0
- package/dist/integrations/solid-start.mjs +14 -0
- package/dist/integrations/svelte-kit.d.mts +28 -0
- package/dist/integrations/svelte-kit.mjs +56 -0
- package/dist/integrations/tanstack-start-solid.d.mts +27 -0
- package/dist/integrations/tanstack-start-solid.mjs +56 -0
- package/dist/integrations/tanstack-start.d.mts +27 -0
- package/dist/integrations/tanstack-start.mjs +56 -0
- package/dist/oauth2/account-fields.mjs +51 -0
- package/dist/oauth2/account-key.mjs +42 -0
- package/dist/oauth2/callback.mjs +67 -0
- package/dist/oauth2/dpop-client.d.mts +1 -0
- package/dist/oauth2/dpop-client.mjs +2 -0
- package/dist/oauth2/errors.mjs +48 -0
- package/dist/oauth2/index.d.mts +5 -0
- package/dist/oauth2/index.mjs +5 -0
- package/dist/oauth2/link-account.d.mts +126 -0
- package/dist/oauth2/link-account.mjs +429 -0
- package/dist/oauth2/state.d.mts +49 -0
- package/dist/oauth2/state.mjs +66 -0
- package/dist/oauth2/utils.d.mts +21 -0
- package/dist/oauth2/utils.mjs +44 -0
- package/dist/package.mjs +3 -0
- package/dist/plugins/access/access.d.mts +13 -0
- package/dist/plugins/access/access.mjs +77 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +1 -0
- package/dist/plugins/access/types.d.mts +20 -0
- package/dist/plugins/additional-fields/client.d.mts +96 -0
- package/dist/plugins/additional-fields/client.mjs +10 -0
- package/dist/plugins/admin/access/index.d.mts +2 -0
- package/dist/plugins/admin/access/index.mjs +1 -0
- package/dist/plugins/admin/access/statement.d.mts +49 -0
- package/dist/plugins/admin/access/statement.mjs +53 -0
- package/dist/plugins/admin/admin.d.mts +908 -0
- package/dist/plugins/admin/admin.mjs +90 -0
- package/dist/plugins/admin/client.d.mts +84 -0
- package/dist/plugins/admin/client.mjs +38 -0
- package/dist/plugins/admin/error-codes.d.mts +30 -0
- package/dist/plugins/admin/error-codes.mjs +33 -0
- package/dist/plugins/admin/has-permission.mjs +11 -0
- package/dist/plugins/admin/index.d.mts +3 -0
- package/dist/plugins/admin/index.mjs +1 -0
- package/dist/plugins/admin/routes.mjs +940 -0
- package/dist/plugins/admin/schema.d.mts +37 -0
- package/dist/plugins/admin/schema.mjs +32 -0
- package/dist/plugins/admin/types.d.mts +89 -0
- package/dist/plugins/anonymous/client.d.mts +28 -0
- package/dist/plugins/anonymous/client.mjs +20 -0
- package/dist/plugins/anonymous/error-codes.d.mts +10 -0
- package/dist/plugins/anonymous/error-codes.mjs +13 -0
- package/dist/plugins/anonymous/index.d.mts +170 -0
- package/dist/plugins/anonymous/index.mjs +220 -0
- package/dist/plugins/anonymous/schema.d.mts +12 -0
- package/dist/plugins/anonymous/schema.mjs +8 -0
- package/dist/plugins/anonymous/types.d.mts +62 -0
- package/dist/plugins/bearer/index.d.mts +39 -0
- package/dist/plugins/bearer/index.mjs +73 -0
- package/dist/plugins/captcha/constants.d.mts +7 -0
- package/dist/plugins/captcha/constants.mjs +27 -0
- package/dist/plugins/captcha/error-codes.mjs +12 -0
- package/dist/plugins/captcha/index.d.mts +22 -0
- package/dist/plugins/captcha/index.mjs +84 -0
- package/dist/plugins/captcha/types.d.mts +90 -0
- package/dist/plugins/captcha/utils.mjs +18 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs +26 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +46 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +31 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +26 -0
- package/dist/plugins/captcha/verify-handlers/vercel-botid.mjs +26 -0
- package/dist/plugins/custom-session/client.d.mts +13 -0
- package/dist/plugins/custom-session/client.mjs +6 -0
- package/dist/plugins/custom-session/index.d.mts +65 -0
- package/dist/plugins/custom-session/index.mjs +57 -0
- package/dist/plugins/device-authorization/client.d.mts +13 -0
- package/dist/plugins/device-authorization/client.mjs +17 -0
- package/dist/plugins/device-authorization/error-codes.mjs +18 -0
- package/dist/plugins/device-authorization/index.d.mts +550 -0
- package/dist/plugins/device-authorization/index.mjs +79 -0
- package/dist/plugins/device-authorization/routes.d.mts +96 -0
- package/dist/plugins/device-authorization/routes.mjs +734 -0
- package/dist/plugins/device-authorization/schema.d.mts +15 -0
- package/dist/plugins/device-authorization/schema.mjs +62 -0
- package/dist/plugins/email-otp/client.d.mts +17 -0
- package/dist/plugins/email-otp/client.mjs +16 -0
- package/dist/plugins/email-otp/error-codes.d.mts +5 -0
- package/dist/plugins/email-otp/error-codes.mjs +8 -0
- package/dist/plugins/email-otp/index.d.mts +542 -0
- package/dist/plugins/email-otp/index.mjs +144 -0
- package/dist/plugins/email-otp/otp-token.mjs +66 -0
- package/dist/plugins/email-otp/routes.mjs +774 -0
- package/dist/plugins/email-otp/types.d.mts +105 -0
- package/dist/plugins/email-otp/utils.mjs +16 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +8 -0
- package/dist/plugins/generic-oauth/index.d.mts +57 -0
- package/dist/plugins/generic-oauth/index.mjs +459 -0
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs +48 -0
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +27 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs +61 -0
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +65 -0
- package/dist/plugins/generic-oauth/providers/index.d.mts +11 -0
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs +46 -0
- package/dist/plugins/generic-oauth/providers/line.d.mts +50 -0
- package/dist/plugins/generic-oauth/providers/line.mjs +92 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +35 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +104 -0
- package/dist/plugins/generic-oauth/providers/okta.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs +47 -0
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +25 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs +60 -0
- package/dist/plugins/generic-oauth/providers/slack.d.mts +25 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs +65 -0
- package/dist/plugins/generic-oauth/providers/token-endpoint-audience.mjs +15 -0
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +25 -0
- package/dist/plugins/generic-oauth/providers/yandex.mjs +66 -0
- package/dist/plugins/generic-oauth/types.d.mts +328 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +57 -0
- package/dist/plugins/haveibeenpwned/index.mjs +80 -0
- package/dist/plugins/index.d.mts +76 -0
- package/dist/plugins/index.mjs +53 -0
- package/dist/plugins/jwt/adapter.mjs +78 -0
- package/dist/plugins/jwt/client.d.mts +38 -0
- package/dist/plugins/jwt/client.mjs +18 -0
- package/dist/plugins/jwt/cookie-cache.mjs +71 -0
- package/dist/plugins/jwt/index.d.mts +241 -0
- package/dist/plugins/jwt/index.mjs +213 -0
- package/dist/plugins/jwt/schema.d.mts +30 -0
- package/dist/plugins/jwt/schema.mjs +28 -0
- package/dist/plugins/jwt/sign.d.mts +127 -0
- package/dist/plugins/jwt/sign.mjs +134 -0
- package/dist/plugins/jwt/types.d.mts +255 -0
- package/dist/plugins/jwt/utils.d.mts +36 -0
- package/dist/plugins/jwt/utils.mjs +63 -0
- package/dist/plugins/jwt/verify.d.mts +7 -0
- package/dist/plugins/jwt/verify.mjs +50 -0
- package/dist/plugins/last-login-method/client.d.mts +45 -0
- package/dist/plugins/last-login-method/client.mjs +47 -0
- package/dist/plugins/last-login-method/index.d.mts +121 -0
- package/dist/plugins/last-login-method/index.mjs +98 -0
- package/dist/plugins/magic-link/client.d.mts +6 -0
- package/dist/plugins/magic-link/client.mjs +10 -0
- package/dist/plugins/magic-link/index.d.mts +208 -0
- package/dist/plugins/magic-link/index.mjs +223 -0
- package/dist/plugins/magic-link/utils.mjs +8 -0
- package/dist/plugins/multi-session/client.d.mts +15 -0
- package/dist/plugins/multi-session/client.mjs +18 -0
- package/dist/plugins/multi-session/error-codes.d.mts +3 -0
- package/dist/plugins/multi-session/error-codes.mjs +4 -0
- package/dist/plugins/multi-session/index.d.mts +206 -0
- package/dist/plugins/multi-session/index.mjs +216 -0
- package/dist/plugins/oauth-popup/client.d.mts +74 -0
- package/dist/plugins/oauth-popup/client.mjs +204 -0
- package/dist/plugins/oauth-popup/constants.d.mts +8 -0
- package/dist/plugins/oauth-popup/constants.mjs +10 -0
- package/dist/plugins/oauth-popup/error-codes.d.mts +6 -0
- package/dist/plugins/oauth-popup/error-codes.mjs +9 -0
- package/dist/plugins/oauth-popup/index.d.mts +61 -0
- package/dist/plugins/oauth-popup/index.mjs +232 -0
- package/dist/plugins/oauth-popup/types.d.mts +26 -0
- package/dist/plugins/oauth-proxy/index.d.mts +123 -0
- package/dist/plugins/oauth-proxy/index.mjs +397 -0
- package/dist/plugins/oauth-proxy/utils.mjs +54 -0
- package/dist/plugins/one-tap/client.d.mts +187 -0
- package/dist/plugins/one-tap/client.mjs +208 -0
- package/dist/plugins/one-tap/index.d.mts +117 -0
- package/dist/plugins/one-tap/index.mjs +146 -0
- package/dist/plugins/one-time-token/client.d.mts +7 -0
- package/dist/plugins/one-time-token/client.mjs +10 -0
- package/dist/plugins/one-time-token/index.d.mts +128 -0
- package/dist/plugins/one-time-token/index.mjs +106 -0
- package/dist/plugins/one-time-token/utils.mjs +8 -0
- package/dist/plugins/open-api/generator.d.mts +124 -0
- package/dist/plugins/open-api/generator.mjs +557 -0
- package/dist/plugins/open-api/index.d.mts +93 -0
- package/dist/plugins/open-api/index.mjs +64 -0
- package/dist/plugins/open-api/logo.mjs +12 -0
- package/dist/plugins/organization/access/index.d.mts +2 -0
- package/dist/plugins/organization/access/index.mjs +1 -0
- package/dist/plugins/organization/access/statement.d.mts +111 -0
- package/dist/plugins/organization/access/statement.mjs +76 -0
- package/dist/plugins/organization/adapter.d.mts +786 -0
- package/dist/plugins/organization/adapter.mjs +821 -0
- package/dist/plugins/organization/call.mjs +14 -0
- package/dist/plugins/organization/client.d.mts +375 -0
- package/dist/plugins/organization/client.mjs +108 -0
- package/dist/plugins/organization/error-codes.d.mts +62 -0
- package/dist/plugins/organization/error-codes.mjs +65 -0
- package/dist/plugins/organization/has-permission.d.mts +12 -0
- package/dist/plugins/organization/has-permission.mjs +72 -0
- package/dist/plugins/organization/index.d.mts +7 -0
- package/dist/plugins/organization/index.mjs +5 -0
- package/dist/plugins/organization/organization.d.mts +418 -0
- package/dist/plugins/organization/organization.mjs +888 -0
- package/dist/plugins/organization/permission.d.mts +12 -0
- package/dist/plugins/organization/permission.mjs +13 -0
- package/dist/plugins/organization/roles.d.mts +6 -0
- package/dist/plugins/organization/roles.mjs +25 -0
- package/dist/plugins/organization/routes/crud-access-control.d.mts +509 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +674 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +1173 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +619 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +1010 -0
- package/dist/plugins/organization/routes/crud-members.mjs +515 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +914 -0
- package/dist/plugins/organization/routes/crud-org.mjs +465 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +1235 -0
- package/dist/plugins/organization/routes/crud-team.mjs +767 -0
- package/dist/plugins/organization/schema.d.mts +388 -0
- package/dist/plugins/organization/schema.mjs +64 -0
- package/dist/plugins/organization/types.d.mts +688 -0
- package/dist/plugins/phone-number/client.d.mts +29 -0
- package/dist/plugins/phone-number/client.mjs +18 -0
- package/dist/plugins/phone-number/error-codes.d.mts +16 -0
- package/dist/plugins/phone-number/error-codes.mjs +19 -0
- package/dist/plugins/phone-number/index.d.mts +376 -0
- package/dist/plugins/phone-number/index.mjs +72 -0
- package/dist/plugins/phone-number/routes.mjs +612 -0
- package/dist/plugins/phone-number/schema.d.mts +19 -0
- package/dist/plugins/phone-number/schema.mjs +17 -0
- package/dist/plugins/phone-number/types.d.mts +119 -0
- package/dist/plugins/siwe/client.d.mts +10 -0
- package/dist/plugins/siwe/client.mjs +14 -0
- package/dist/plugins/siwe/index.d.mts +58 -0
- package/dist/plugins/siwe/index.mjs +288 -0
- package/dist/plugins/siwe/parse-message.mjs +57 -0
- package/dist/plugins/siwe/schema.d.mts +32 -0
- package/dist/plugins/siwe/schema.mjs +29 -0
- package/dist/plugins/siwe/types.d.mts +41 -0
- package/dist/plugins/test-utils/auth-helpers.mjs +34 -0
- package/dist/plugins/test-utils/cookie-builder.mjs +54 -0
- package/dist/plugins/test-utils/db-helpers.mjs +64 -0
- package/dist/plugins/test-utils/factories.mjs +37 -0
- package/dist/plugins/test-utils/index.d.mts +69 -0
- package/dist/plugins/test-utils/index.mjs +96 -0
- package/dist/plugins/test-utils/otp-sink.mjs +20 -0
- package/dist/plugins/test-utils/types.d.mts +49 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +286 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs +354 -0
- package/dist/plugins/two-factor/claim.d.mts +86 -0
- package/dist/plugins/two-factor/claim.mjs +171 -0
- package/dist/plugins/two-factor/client.d.mts +76 -0
- package/dist/plugins/two-factor/client.mjs +40 -0
- package/dist/plugins/two-factor/constant.d.mts +7 -0
- package/dist/plugins/two-factor/constant.mjs +12 -0
- package/dist/plugins/two-factor/error-code.d.mts +20 -0
- package/dist/plugins/two-factor/error-code.mjs +23 -0
- package/dist/plugins/two-factor/index.d.mts +746 -0
- package/dist/plugins/two-factor/index.mjs +493 -0
- package/dist/plugins/two-factor/otp/index.d.mts +211 -0
- package/dist/plugins/two-factor/otp/index.mjs +262 -0
- package/dist/plugins/two-factor/passkey.mjs +47 -0
- package/dist/plugins/two-factor/schema.d.mts +66 -0
- package/dist/plugins/two-factor/schema.mjs +66 -0
- package/dist/plugins/two-factor/totp/index.d.mts +214 -0
- package/dist/plugins/two-factor/totp/index.mjs +290 -0
- package/dist/plugins/two-factor/types.d.mts +112 -0
- package/dist/plugins/two-factor/utils.mjs +8 -0
- package/dist/plugins/two-factor/verify-two-factor.d.mts +121 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs +314 -0
- package/dist/plugins/username/client.d.mts +34 -0
- package/dist/plugins/username/client.mjs +16 -0
- package/dist/plugins/username/error-codes.d.mts +11 -0
- package/dist/plugins/username/error-codes.mjs +14 -0
- package/dist/plugins/username/index.d.mts +319 -0
- package/dist/plugins/username/index.mjs +304 -0
- package/dist/plugins/username/schema.d.mts +45 -0
- package/dist/plugins/username/schema.mjs +24 -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 +153 -0
- package/dist/test-utils/headers.d.mts +5 -0
- package/dist/test-utils/headers.mjs +16 -0
- package/dist/test-utils/http-test-instance.d.mts +420 -0
- package/dist/test-utils/http-test-instance.mjs +106 -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 +55 -0
- package/dist/test-utils/test-instance.mjs +252 -0
- package/dist/types/adapter.d.mts +2 -0
- package/dist/types/api.d.mts +24 -0
- package/dist/types/auth.d.mts +28 -0
- package/dist/types/helper.d.mts +23 -0
- package/dist/types/index.d.mts +10 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +7 -0
- package/dist/types/plugins.d.mts +16 -0
- package/dist/utils/constants.mjs +3 -0
- package/dist/utils/date.mjs +5 -0
- package/dist/utils/hashing.mjs +17 -0
- package/dist/utils/hide-metadata.d.mts +2 -0
- package/dist/utils/hide-metadata.mjs +1 -0
- package/dist/utils/index.d.mts +5 -0
- package/dist/utils/is-api-error.d.mts +2 -0
- package/dist/utils/is-api-error.mjs +1 -0
- package/dist/utils/is-atom.mjs +5 -0
- package/dist/utils/is-promise.mjs +5 -0
- package/dist/utils/middleware-response.mjs +9 -0
- package/dist/utils/password.mjs +90 -0
- package/dist/utils/plugin-helper.mjs +13 -0
- package/dist/utils/request.mjs +22 -0
- package/dist/utils/shim.mjs +21 -0
- package/dist/utils/time.d.mts +46 -0
- package/dist/utils/time.mjs +97 -0
- package/dist/utils/url.d.mts +74 -0
- package/dist/utils/url.mjs +237 -0
- package/dist/utils/validate-user-info.mjs +43 -0
- package/dist/utils/wildcard.mjs +107 -0
- package/dist/version.mjs +4 -0
- package/package.json +601 -3
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
2
|
+
import { UsernameSchema } from "./schema.mjs";
|
|
3
|
+
import { USERNAME_ERROR_CODES } from "./error-codes.mjs";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
declare module "@entro314labs/entro-auth-core" {
|
|
6
|
+
interface EntroAuthPluginRegistry<AuthOptions, Options> {
|
|
7
|
+
username: {
|
|
8
|
+
creator: typeof username;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export type UsernameOptions = {
|
|
13
|
+
schema?: InferOptionSchema<UsernameSchema> | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The minimum length of the username
|
|
16
|
+
*
|
|
17
|
+
* @default 3
|
|
18
|
+
*/
|
|
19
|
+
minUsernameLength?: number | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The maximum length of the username
|
|
22
|
+
*
|
|
23
|
+
* @default 30
|
|
24
|
+
*/
|
|
25
|
+
maxUsernameLength?: number | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* A function to validate the username
|
|
28
|
+
*
|
|
29
|
+
* By default, the username should only contain alphanumeric characters and underscores
|
|
30
|
+
*/
|
|
31
|
+
usernameValidator?: ((username: string) => boolean | Promise<boolean>) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* A function to validate the display username
|
|
34
|
+
*
|
|
35
|
+
* By default, no validation is applied to display username
|
|
36
|
+
*/
|
|
37
|
+
displayUsernameValidator?: ((displayUsername: string) => boolean | Promise<boolean>) | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* A function to normalize the username
|
|
40
|
+
*
|
|
41
|
+
* @default (username) => username.toLowerCase()
|
|
42
|
+
*/
|
|
43
|
+
usernameNormalization?: (((username: string) => string) | false) | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* A function to normalize the display username
|
|
46
|
+
*
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
displayUsernameNormalization?: (((displayUsername: string) => string) | false) | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* The order of validation
|
|
52
|
+
*
|
|
53
|
+
* @default { username: "pre-normalization", displayUsername: "pre-normalization" }
|
|
54
|
+
*/
|
|
55
|
+
validationOrder?: {
|
|
56
|
+
/**
|
|
57
|
+
* The order of username validation
|
|
58
|
+
*
|
|
59
|
+
* @default "pre-normalization"
|
|
60
|
+
*/
|
|
61
|
+
username?: "pre-normalization" | "post-normalization";
|
|
62
|
+
/**
|
|
63
|
+
* The order of display username validation
|
|
64
|
+
*
|
|
65
|
+
* @default "pre-normalization"
|
|
66
|
+
*/
|
|
67
|
+
displayUsername?: "pre-normalization" | "post-normalization";
|
|
68
|
+
} | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Whether the username should be immutable
|
|
71
|
+
* When enabled, users cannot update their username after it has been set
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
immutableUsername?: boolean | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Whether to add and maintain a separate `displayUsername` field.
|
|
78
|
+
*
|
|
79
|
+
* When set to `false`, the `displayUsername` field is not added to the user
|
|
80
|
+
* schema, is never written during sign-up/update, and is excluded from the
|
|
81
|
+
* inferred user/session types. Username normalization continues to work.
|
|
82
|
+
*
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
displayUsername?: boolean | undefined;
|
|
86
|
+
};
|
|
87
|
+
declare const usernameImpl: <IncludeDisplayUsername extends boolean>(options: UsernameOptions | undefined, includeDisplayUsername: IncludeDisplayUsername) => {
|
|
88
|
+
id: "username";
|
|
89
|
+
version: string;
|
|
90
|
+
init(ctx: import("@entro314labs/entro-auth-core").AuthContext): {
|
|
91
|
+
options: {
|
|
92
|
+
databaseHooks: {
|
|
93
|
+
user: {
|
|
94
|
+
create: {
|
|
95
|
+
before(user: {
|
|
96
|
+
id: string;
|
|
97
|
+
createdAt: Date;
|
|
98
|
+
updatedAt: Date;
|
|
99
|
+
email: string;
|
|
100
|
+
emailVerified: boolean;
|
|
101
|
+
name: string;
|
|
102
|
+
image?: string | null | undefined;
|
|
103
|
+
} & Record<string, unknown>, context: import("@entro314labs/entro-auth-core").GenericEndpointContext | null): Promise<{
|
|
104
|
+
data: {
|
|
105
|
+
displayUsername?: string | undefined;
|
|
106
|
+
username: string;
|
|
107
|
+
id: string;
|
|
108
|
+
createdAt: Date;
|
|
109
|
+
updatedAt: Date;
|
|
110
|
+
email: string;
|
|
111
|
+
emailVerified: boolean;
|
|
112
|
+
name: string;
|
|
113
|
+
image?: string | null | undefined;
|
|
114
|
+
};
|
|
115
|
+
} | {
|
|
116
|
+
data: {
|
|
117
|
+
displayUsername?: string | undefined;
|
|
118
|
+
id: string;
|
|
119
|
+
createdAt: Date;
|
|
120
|
+
updatedAt: Date;
|
|
121
|
+
email: string;
|
|
122
|
+
emailVerified: boolean;
|
|
123
|
+
name: string;
|
|
124
|
+
image?: string | null | undefined;
|
|
125
|
+
};
|
|
126
|
+
}>;
|
|
127
|
+
};
|
|
128
|
+
update: {
|
|
129
|
+
before(user: Partial<{
|
|
130
|
+
id: string;
|
|
131
|
+
createdAt: Date;
|
|
132
|
+
updatedAt: Date;
|
|
133
|
+
email: string;
|
|
134
|
+
emailVerified: boolean;
|
|
135
|
+
name: string;
|
|
136
|
+
image?: string | null | undefined;
|
|
137
|
+
}> & Record<string, unknown>, context: import("@entro314labs/entro-auth-core").GenericEndpointContext | null): Promise<{
|
|
138
|
+
data: {
|
|
139
|
+
displayUsername?: string | undefined;
|
|
140
|
+
username: string;
|
|
141
|
+
id?: string | undefined;
|
|
142
|
+
createdAt?: Date | undefined;
|
|
143
|
+
updatedAt?: Date | undefined;
|
|
144
|
+
email?: string | undefined;
|
|
145
|
+
emailVerified?: boolean | undefined;
|
|
146
|
+
name?: string | undefined;
|
|
147
|
+
image?: string | null | undefined;
|
|
148
|
+
};
|
|
149
|
+
} | {
|
|
150
|
+
data: {
|
|
151
|
+
displayUsername?: string | undefined;
|
|
152
|
+
id?: string | undefined;
|
|
153
|
+
createdAt?: Date | undefined;
|
|
154
|
+
updatedAt?: Date | undefined;
|
|
155
|
+
email?: string | undefined;
|
|
156
|
+
emailVerified?: boolean | undefined;
|
|
157
|
+
name?: string | undefined;
|
|
158
|
+
image?: string | null | undefined;
|
|
159
|
+
};
|
|
160
|
+
}>;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
endpoints: {
|
|
167
|
+
signInUsername: import("better-call").StrictEndpoint<"/sign-in/username", {
|
|
168
|
+
method: "POST";
|
|
169
|
+
body: z.ZodObject<{
|
|
170
|
+
username: z.ZodString;
|
|
171
|
+
password: z.ZodString;
|
|
172
|
+
rememberMe: z.ZodOptional<z.ZodBoolean>;
|
|
173
|
+
callbackURL: z.ZodOptional<z.ZodString>;
|
|
174
|
+
}, z.core.$strip>;
|
|
175
|
+
metadata: {
|
|
176
|
+
openapi: {
|
|
177
|
+
summary: string;
|
|
178
|
+
description: string;
|
|
179
|
+
responses: {
|
|
180
|
+
200: {
|
|
181
|
+
description: string;
|
|
182
|
+
content: {
|
|
183
|
+
"application/json": {
|
|
184
|
+
schema: {
|
|
185
|
+
type: "object";
|
|
186
|
+
properties: {
|
|
187
|
+
redirect: {
|
|
188
|
+
type: string;
|
|
189
|
+
description: string;
|
|
190
|
+
};
|
|
191
|
+
token: {
|
|
192
|
+
type: string;
|
|
193
|
+
description: string;
|
|
194
|
+
};
|
|
195
|
+
url: {
|
|
196
|
+
type: string;
|
|
197
|
+
nullable: boolean;
|
|
198
|
+
description: string;
|
|
199
|
+
};
|
|
200
|
+
user: {
|
|
201
|
+
$ref: string;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
required: string[];
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
422: {
|
|
210
|
+
description: string;
|
|
211
|
+
content: {
|
|
212
|
+
"application/json": {
|
|
213
|
+
schema: {
|
|
214
|
+
type: "object";
|
|
215
|
+
properties: {
|
|
216
|
+
message: {
|
|
217
|
+
type: string;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
}, {
|
|
228
|
+
redirect: boolean;
|
|
229
|
+
token: string;
|
|
230
|
+
url: string | undefined;
|
|
231
|
+
user: {
|
|
232
|
+
id: string;
|
|
233
|
+
createdAt: Date;
|
|
234
|
+
updatedAt: Date;
|
|
235
|
+
email: string;
|
|
236
|
+
emailVerified: boolean;
|
|
237
|
+
name: string;
|
|
238
|
+
image?: string | null | undefined;
|
|
239
|
+
} & {
|
|
240
|
+
username: string;
|
|
241
|
+
displayUsername: string;
|
|
242
|
+
};
|
|
243
|
+
}>;
|
|
244
|
+
isUsernameAvailable: import("better-call").StrictEndpoint<"/is-username-available", {
|
|
245
|
+
method: "POST";
|
|
246
|
+
body: z.ZodObject<{
|
|
247
|
+
username: z.ZodString;
|
|
248
|
+
}, z.core.$strip>;
|
|
249
|
+
}, {
|
|
250
|
+
available: boolean;
|
|
251
|
+
}>;
|
|
252
|
+
};
|
|
253
|
+
schema: {
|
|
254
|
+
user: {
|
|
255
|
+
fields: IncludeDisplayUsername extends false ? Pick<{
|
|
256
|
+
username: {
|
|
257
|
+
type: "string";
|
|
258
|
+
required: false;
|
|
259
|
+
sortable: true;
|
|
260
|
+
unique: true;
|
|
261
|
+
returned: true;
|
|
262
|
+
transform: {
|
|
263
|
+
input(value: import("@entro314labs/entro-auth-core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
displayUsername: {
|
|
267
|
+
type: "string";
|
|
268
|
+
required: false;
|
|
269
|
+
transform: {
|
|
270
|
+
input(value: import("@entro314labs/entro-auth-core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
}, "username"> : {
|
|
274
|
+
username: {
|
|
275
|
+
type: "string";
|
|
276
|
+
required: false;
|
|
277
|
+
sortable: true;
|
|
278
|
+
unique: true;
|
|
279
|
+
returned: true;
|
|
280
|
+
transform: {
|
|
281
|
+
input(value: import("@entro314labs/entro-auth-core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
displayUsername: {
|
|
285
|
+
type: "string";
|
|
286
|
+
required: false;
|
|
287
|
+
transform: {
|
|
288
|
+
input(value: import("@entro314labs/entro-auth-core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
hooks: {
|
|
295
|
+
before: {
|
|
296
|
+
matcher(context: import("@entro314labs/entro-auth-core").HookEndpointContext): boolean;
|
|
297
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
298
|
+
}[];
|
|
299
|
+
};
|
|
300
|
+
options: UsernameOptions | undefined;
|
|
301
|
+
$ERROR_CODES: {
|
|
302
|
+
EMAIL_NOT_VERIFIED: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"EMAIL_NOT_VERIFIED">;
|
|
303
|
+
UNEXPECTED_ERROR: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"UNEXPECTED_ERROR">;
|
|
304
|
+
INVALID_USERNAME_OR_PASSWORD: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"INVALID_USERNAME_OR_PASSWORD">;
|
|
305
|
+
USERNAME_IS_ALREADY_TAKEN: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"USERNAME_IS_ALREADY_TAKEN">;
|
|
306
|
+
USERNAME_TOO_SHORT: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"USERNAME_TOO_SHORT">;
|
|
307
|
+
USERNAME_TOO_LONG: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"USERNAME_TOO_LONG">;
|
|
308
|
+
INVALID_USERNAME: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"INVALID_USERNAME">;
|
|
309
|
+
INVALID_DISPLAY_USERNAME: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"INVALID_DISPLAY_USERNAME">;
|
|
310
|
+
USERNAME_IS_IMMUTABLE: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"USERNAME_IS_IMMUTABLE">;
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
export type UsernamePlugin = ReturnType<typeof usernameImpl<true>>;
|
|
314
|
+
export type UsernamePluginWithoutDisplayUsername = ReturnType<typeof usernameImpl<false>>;
|
|
315
|
+
export declare function username(options: UsernameOptions & {
|
|
316
|
+
displayUsername: false;
|
|
317
|
+
}): UsernamePluginWithoutDisplayUsername;
|
|
318
|
+
export declare function username(options?: UsernameOptions): UsernamePlugin;
|
|
319
|
+
export { USERNAME_ERROR_CODES };
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { createEmailVerificationToken } from "../../api/routes/email-verification.mjs";
|
|
2
|
+
import { setSessionCookie } from "../../cookies/index.mjs";
|
|
3
|
+
import { mergeSchema, parseUserOutput } from "../../db/schema.mjs";
|
|
4
|
+
import { assertPasswordNotTooLong } from "../../utils/password.mjs";
|
|
5
|
+
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
6
|
+
import { USERNAME_ERROR_CODES } from "./error-codes.mjs";
|
|
7
|
+
import { getSchema } from "./schema.mjs";
|
|
8
|
+
import { getCurrentAdapter } from "@entro314labs/entro-auth-core/context";
|
|
9
|
+
import { APIError, BASE_ERROR_CODES } from "@entro314labs/entro-auth-core/error";
|
|
10
|
+
import { createAuthEndpoint, createAuthMiddleware } from "@entro314labs/entro-auth-core/api";
|
|
11
|
+
import * as z from "zod";
|
|
12
|
+
// src/plugins/username/index.ts
|
|
13
|
+
function defaultUsernameValidator(username) {
|
|
14
|
+
return /^[a-zA-Z0-9_.]+$/.test(username);
|
|
15
|
+
}
|
|
16
|
+
const signInUsernameBodySchema = z.object({
|
|
17
|
+
username: z.string().meta({ description: "The username of the user" }),
|
|
18
|
+
password: z.string().meta({ description: "The password of the user" }),
|
|
19
|
+
rememberMe: z.boolean().meta({ description: "Remember the user session" }).optional(),
|
|
20
|
+
callbackURL: z.string().meta({ description: "URL to redirect to after sign in (also used as the redirect target for email verification when required)" }).optional()
|
|
21
|
+
});
|
|
22
|
+
const isUsernameAvailableBodySchema = z.object({ username: z.string().meta({ description: "The username to check" }) });
|
|
23
|
+
const usernameImpl = (options, includeDisplayUsername) => {
|
|
24
|
+
const normalizer = (username) => {
|
|
25
|
+
if (options?.usernameNormalization === false) return username;
|
|
26
|
+
if (options?.usernameNormalization) return options.usernameNormalization(username);
|
|
27
|
+
return username.toLowerCase();
|
|
28
|
+
};
|
|
29
|
+
const displayUsernameNormalizer = (displayUsername) => {
|
|
30
|
+
return options?.displayUsernameNormalization ? options.displayUsernameNormalization(displayUsername) : displayUsername;
|
|
31
|
+
};
|
|
32
|
+
const minUsernameLength = options?.minUsernameLength || 3;
|
|
33
|
+
const maxUsernameLength = options?.maxUsernameLength || 30;
|
|
34
|
+
const validator = options?.usernameValidator || defaultUsernameValidator;
|
|
35
|
+
const pathsWithHttpHookValidation = ["/sign-up/email", "/update-user"];
|
|
36
|
+
const getUsernameToValidate = (username) => options?.validationOrder?.username === "post-normalization" ? normalizer(username) : username;
|
|
37
|
+
async function validateUsernameValue(username) {
|
|
38
|
+
const usernameToValidate = getUsernameToValidate(username);
|
|
39
|
+
if (usernameToValidate.length < minUsernameLength) return USERNAME_ERROR_CODES.USERNAME_TOO_SHORT;
|
|
40
|
+
if (usernameToValidate.length > maxUsernameLength) return USERNAME_ERROR_CODES.USERNAME_TOO_LONG;
|
|
41
|
+
if (!await validator(usernameToValidate)) return USERNAME_ERROR_CODES.INVALID_USERNAME;
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
async function validateUsername(username, displayUsername, adapter, currentUserId) {
|
|
45
|
+
const validationError = await validateUsernameValue(username);
|
|
46
|
+
if (validationError) throw APIError.from("BAD_REQUEST", validationError);
|
|
47
|
+
const normalizedUsername = normalizer(username);
|
|
48
|
+
const existingUser = await adapter.findOne({
|
|
49
|
+
model: "user",
|
|
50
|
+
where: [{
|
|
51
|
+
field: "username",
|
|
52
|
+
value: normalizedUsername
|
|
53
|
+
}]
|
|
54
|
+
});
|
|
55
|
+
if (existingUser) {
|
|
56
|
+
if (!currentUserId || existingUser.id !== currentUserId) throw APIError.from("BAD_REQUEST", USERNAME_ERROR_CODES.USERNAME_IS_ALREADY_TAKEN);
|
|
57
|
+
}
|
|
58
|
+
if (displayUsername && options?.displayUsernameValidator) {
|
|
59
|
+
const displayUsernameToValidate = options?.validationOrder?.displayUsername === "post-normalization" ? displayUsernameNormalizer(displayUsername) : displayUsername;
|
|
60
|
+
if (!await options.displayUsernameValidator(displayUsernameToValidate)) throw APIError.from("BAD_REQUEST", USERNAME_ERROR_CODES.INVALID_DISPLAY_USERNAME);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
id: "username",
|
|
65
|
+
version: PACKAGE_VERSION,
|
|
66
|
+
init(ctx) {
|
|
67
|
+
return { options: { databaseHooks: { user: {
|
|
68
|
+
create: { async before(user, context) {
|
|
69
|
+
const username = "username" in user ? user.username : null;
|
|
70
|
+
const displayUsername = "displayUsername" in user ? user.displayUsername : null;
|
|
71
|
+
const currentPath = context?.path;
|
|
72
|
+
const skipValidation = currentPath && pathsWithHttpHookValidation.includes(currentPath);
|
|
73
|
+
if (username) {
|
|
74
|
+
if (!skipValidation) await validateUsername(username, displayUsername, await getCurrentAdapter(ctx.adapter));
|
|
75
|
+
return { data: {
|
|
76
|
+
...user,
|
|
77
|
+
username: normalizer(username),
|
|
78
|
+
...includeDisplayUsername ? { displayUsername: displayUsername ? displayUsernameNormalizer(displayUsername) : username } : {}
|
|
79
|
+
} };
|
|
80
|
+
}
|
|
81
|
+
return { data: {
|
|
82
|
+
...user,
|
|
83
|
+
...includeDisplayUsername && displayUsername ? { displayUsername: displayUsernameNormalizer(displayUsername) } : {}
|
|
84
|
+
} };
|
|
85
|
+
} },
|
|
86
|
+
update: { async before(user, context) {
|
|
87
|
+
const username = "username" in user ? user.username : null;
|
|
88
|
+
const displayUsername = "displayUsername" in user ? user.displayUsername : null;
|
|
89
|
+
const currentPath = context?.path;
|
|
90
|
+
const skipValidation = currentPath && pathsWithHttpHookValidation.includes(currentPath);
|
|
91
|
+
if (typeof username === "string" && currentPath === "/update-user") {
|
|
92
|
+
const session = context?.context?.session;
|
|
93
|
+
const normalizedUsername = normalizer(username);
|
|
94
|
+
if (options?.immutableUsername && session?.user.username && session.user.username !== normalizedUsername) throw APIError.from("BAD_REQUEST", USERNAME_ERROR_CODES.USERNAME_IS_IMMUTABLE);
|
|
95
|
+
const existingUser = await (await getCurrentAdapter(ctx.adapter)).findOne({
|
|
96
|
+
model: "user",
|
|
97
|
+
where: [{
|
|
98
|
+
field: "username",
|
|
99
|
+
value: normalizedUsername
|
|
100
|
+
}]
|
|
101
|
+
});
|
|
102
|
+
if (existingUser && existingUser.id !== session?.user.id) throw APIError.from("BAD_REQUEST", USERNAME_ERROR_CODES.USERNAME_IS_ALREADY_TAKEN);
|
|
103
|
+
}
|
|
104
|
+
if (username) {
|
|
105
|
+
if (!skipValidation) {
|
|
106
|
+
const currentUserId = context?.context?.session?.user?.id || ("id" in user ? user.id : null);
|
|
107
|
+
await validateUsername(username, displayUsername, await getCurrentAdapter(ctx.adapter), currentUserId);
|
|
108
|
+
}
|
|
109
|
+
return { data: {
|
|
110
|
+
...user,
|
|
111
|
+
username: normalizer(username),
|
|
112
|
+
...includeDisplayUsername && displayUsername ? { displayUsername: displayUsernameNormalizer(displayUsername) } : {}
|
|
113
|
+
} };
|
|
114
|
+
}
|
|
115
|
+
return { data: {
|
|
116
|
+
...user,
|
|
117
|
+
...includeDisplayUsername && displayUsername ? { displayUsername: displayUsernameNormalizer(displayUsername) } : {}
|
|
118
|
+
} };
|
|
119
|
+
} }
|
|
120
|
+
} } } };
|
|
121
|
+
},
|
|
122
|
+
endpoints: {
|
|
123
|
+
signInUsername: createAuthEndpoint("/sign-in/username", {
|
|
124
|
+
method: "POST",
|
|
125
|
+
body: signInUsernameBodySchema,
|
|
126
|
+
metadata: { openapi: {
|
|
127
|
+
summary: "Sign in with username",
|
|
128
|
+
description: "Sign in with username",
|
|
129
|
+
responses: {
|
|
130
|
+
200: {
|
|
131
|
+
description: "Success",
|
|
132
|
+
content: { "application/json": { schema: {
|
|
133
|
+
type: "object",
|
|
134
|
+
properties: {
|
|
135
|
+
redirect: {
|
|
136
|
+
type: "boolean",
|
|
137
|
+
description: "Whether the client should follow the Location header. True when callbackURL was provided."
|
|
138
|
+
},
|
|
139
|
+
token: {
|
|
140
|
+
type: "string",
|
|
141
|
+
description: "Session token for the authenticated session"
|
|
142
|
+
},
|
|
143
|
+
url: {
|
|
144
|
+
type: "string",
|
|
145
|
+
nullable: true,
|
|
146
|
+
description: "The callbackURL echoed back so the client can redirect."
|
|
147
|
+
},
|
|
148
|
+
user: { $ref: "#/components/schemas/User" }
|
|
149
|
+
},
|
|
150
|
+
required: [
|
|
151
|
+
"redirect",
|
|
152
|
+
"token",
|
|
153
|
+
"user"
|
|
154
|
+
]
|
|
155
|
+
} } }
|
|
156
|
+
},
|
|
157
|
+
422: {
|
|
158
|
+
description: "Unprocessable Entity. Validation error",
|
|
159
|
+
content: { "application/json": { schema: {
|
|
160
|
+
type: "object",
|
|
161
|
+
properties: { message: { type: "string" } }
|
|
162
|
+
} } }
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} }
|
|
166
|
+
}, async (ctx) => {
|
|
167
|
+
if (!ctx.body.username || !ctx.body.password) {
|
|
168
|
+
ctx.context.logger.warn("Username or password not found");
|
|
169
|
+
throw APIError.from("UNAUTHORIZED", USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD);
|
|
170
|
+
}
|
|
171
|
+
const validationError = await validateUsernameValue(ctx.body.username);
|
|
172
|
+
if (validationError) throw APIError.from("UNPROCESSABLE_ENTITY", validationError);
|
|
173
|
+
assertPasswordNotTooLong(ctx, ctx.body.password);
|
|
174
|
+
const user = await ctx.context.adapter.findOne({
|
|
175
|
+
model: "user",
|
|
176
|
+
where: [{
|
|
177
|
+
field: "username",
|
|
178
|
+
value: normalizer(ctx.body.username)
|
|
179
|
+
}]
|
|
180
|
+
});
|
|
181
|
+
if (!user) {
|
|
182
|
+
await ctx.context.password.hash(ctx.body.password);
|
|
183
|
+
ctx.context.logger.warn("User not found");
|
|
184
|
+
throw APIError.from("UNAUTHORIZED", USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD);
|
|
185
|
+
}
|
|
186
|
+
const account = await ctx.context.internalAdapter.findCredentialAccount(user.id);
|
|
187
|
+
if (!account) throw APIError.from("UNAUTHORIZED", USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD);
|
|
188
|
+
const currentPassword = account?.password;
|
|
189
|
+
if (!currentPassword) {
|
|
190
|
+
ctx.context.logger.warn("Password not found");
|
|
191
|
+
throw APIError.from("UNAUTHORIZED", USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD);
|
|
192
|
+
}
|
|
193
|
+
if (!await ctx.context.password.verify({
|
|
194
|
+
hash: currentPassword,
|
|
195
|
+
password: ctx.body.password
|
|
196
|
+
})) {
|
|
197
|
+
ctx.context.logger.warn("Invalid password");
|
|
198
|
+
throw APIError.from("UNAUTHORIZED", USERNAME_ERROR_CODES.INVALID_USERNAME_OR_PASSWORD);
|
|
199
|
+
}
|
|
200
|
+
if (ctx.context.options?.emailAndPassword?.requireEmailVerification && !user.emailVerified) {
|
|
201
|
+
if (!ctx.context.options?.emailVerification?.sendVerificationEmail) throw APIError.from("FORBIDDEN", USERNAME_ERROR_CODES.EMAIL_NOT_VERIFIED);
|
|
202
|
+
if (ctx.context.options?.emailVerification?.sendOnSignIn) {
|
|
203
|
+
const token = await createEmailVerificationToken(ctx.context.secret, user.email, void 0, ctx.context.options.emailVerification?.expiresIn, { userId: user.id });
|
|
204
|
+
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${encodeURIComponent(ctx.body.callbackURL || "/")}`;
|
|
205
|
+
await ctx.context.runInBackgroundOrAwait(ctx.context.options.emailVerification.sendVerificationEmail({
|
|
206
|
+
user,
|
|
207
|
+
url,
|
|
208
|
+
token
|
|
209
|
+
}, ctx.request));
|
|
210
|
+
}
|
|
211
|
+
throw APIError.from("FORBIDDEN", USERNAME_ERROR_CODES.EMAIL_NOT_VERIFIED);
|
|
212
|
+
}
|
|
213
|
+
const session = await ctx.context.internalAdapter.createSession(user.id, ctx.body.rememberMe === false);
|
|
214
|
+
if (!session) throw APIError.from("INTERNAL_SERVER_ERROR", BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION);
|
|
215
|
+
await setSessionCookie(ctx, {
|
|
216
|
+
session,
|
|
217
|
+
user
|
|
218
|
+
}, ctx.body.rememberMe === false);
|
|
219
|
+
if (ctx.body.callbackURL) ctx.setHeader("Location", ctx.body.callbackURL);
|
|
220
|
+
return ctx.json({
|
|
221
|
+
redirect: !!ctx.body.callbackURL,
|
|
222
|
+
token: session.token,
|
|
223
|
+
url: ctx.body.callbackURL,
|
|
224
|
+
user: parseUserOutput(ctx.context.options, user)
|
|
225
|
+
});
|
|
226
|
+
}),
|
|
227
|
+
isUsernameAvailable: createAuthEndpoint("/is-username-available", {
|
|
228
|
+
method: "POST",
|
|
229
|
+
body: isUsernameAvailableBodySchema
|
|
230
|
+
}, async (ctx) => {
|
|
231
|
+
const username = ctx.body.username;
|
|
232
|
+
if (!username) throw APIError.from("UNPROCESSABLE_ENTITY", USERNAME_ERROR_CODES.INVALID_USERNAME);
|
|
233
|
+
const validationError = await validateUsernameValue(username);
|
|
234
|
+
if (validationError) throw APIError.from("UNPROCESSABLE_ENTITY", validationError);
|
|
235
|
+
if (await ctx.context.adapter.findOne({
|
|
236
|
+
model: "user",
|
|
237
|
+
where: [{
|
|
238
|
+
field: "username",
|
|
239
|
+
value: normalizer(username)
|
|
240
|
+
}]
|
|
241
|
+
})) return ctx.json({ available: false });
|
|
242
|
+
return ctx.json({ available: true });
|
|
243
|
+
})
|
|
244
|
+
},
|
|
245
|
+
schema: mergeSchema(getSchema({
|
|
246
|
+
username: normalizer,
|
|
247
|
+
displayUsername: displayUsernameNormalizer
|
|
248
|
+
}, includeDisplayUsername), options?.schema),
|
|
249
|
+
hooks: { before: [
|
|
250
|
+
{
|
|
251
|
+
matcher(context) {
|
|
252
|
+
return context.path === "/sign-up/email";
|
|
253
|
+
},
|
|
254
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
255
|
+
if (typeof ctx.body?.displayUsername !== "string" || ctx.body.username !== void 0) return;
|
|
256
|
+
if (!await validateUsernameValue(ctx.body.displayUsername)) ctx.body.username = ctx.body.displayUsername;
|
|
257
|
+
})
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
matcher(context) {
|
|
261
|
+
return context.path === "/sign-up/email" || context.path === "/update-user";
|
|
262
|
+
},
|
|
263
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
264
|
+
const username = ctx.body?.username;
|
|
265
|
+
if (username !== void 0 && typeof username === "string") {
|
|
266
|
+
const validationError = await validateUsernameValue(username);
|
|
267
|
+
if (validationError) throw APIError.from("BAD_REQUEST", validationError);
|
|
268
|
+
if (ctx.path === "/sign-up/email") {
|
|
269
|
+
if (await ctx.context.adapter.findOne({
|
|
270
|
+
model: "user",
|
|
271
|
+
where: [{
|
|
272
|
+
field: "username",
|
|
273
|
+
value: normalizer(username)
|
|
274
|
+
}]
|
|
275
|
+
})) throw APIError.from("BAD_REQUEST", USERNAME_ERROR_CODES.USERNAME_IS_ALREADY_TAKEN);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (!includeDisplayUsername) return;
|
|
279
|
+
const displayUsername = typeof ctx.body?.displayUsername === "string" && options?.validationOrder?.displayUsername === "post-normalization" ? displayUsernameNormalizer(ctx.body.displayUsername) : ctx.body?.displayUsername;
|
|
280
|
+
if (displayUsername !== void 0 && typeof displayUsername === "string") {
|
|
281
|
+
if (options?.displayUsernameValidator) {
|
|
282
|
+
if (!await options.displayUsernameValidator(displayUsername)) throw APIError.from("BAD_REQUEST", USERNAME_ERROR_CODES.INVALID_DISPLAY_USERNAME);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
})
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
matcher(context) {
|
|
289
|
+
return context.path === "/sign-up/email";
|
|
290
|
+
},
|
|
291
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
292
|
+
if (!includeDisplayUsername) return;
|
|
293
|
+
if (ctx.body?.username && !ctx.body.displayUsername) ctx.body.displayUsername = ctx.body.username;
|
|
294
|
+
})
|
|
295
|
+
}
|
|
296
|
+
] },
|
|
297
|
+
options,
|
|
298
|
+
$ERROR_CODES: USERNAME_ERROR_CODES
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
function username(options) {
|
|
302
|
+
return usernameImpl(options, options?.displayUsername !== false);
|
|
303
|
+
}
|
|
304
|
+
export { USERNAME_ERROR_CODES, username };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const getSchema: <IncludeDisplayUsername extends boolean = true>(normalizer: {
|
|
2
|
+
username: (username: string) => string;
|
|
3
|
+
displayUsername: (displayUsername: string) => string;
|
|
4
|
+
}, includeDisplayUsername?: IncludeDisplayUsername) => {
|
|
5
|
+
user: {
|
|
6
|
+
fields: IncludeDisplayUsername extends false ? Pick<{
|
|
7
|
+
username: {
|
|
8
|
+
type: "string";
|
|
9
|
+
required: false;
|
|
10
|
+
sortable: true;
|
|
11
|
+
unique: true;
|
|
12
|
+
returned: true;
|
|
13
|
+
transform: {
|
|
14
|
+
input(value: import("@entro314labs/entro-auth-core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
displayUsername: {
|
|
18
|
+
type: "string";
|
|
19
|
+
required: false;
|
|
20
|
+
transform: {
|
|
21
|
+
input(value: import("@entro314labs/entro-auth-core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}, "username"> : {
|
|
25
|
+
username: {
|
|
26
|
+
type: "string";
|
|
27
|
+
required: false;
|
|
28
|
+
sortable: true;
|
|
29
|
+
unique: true;
|
|
30
|
+
returned: true;
|
|
31
|
+
transform: {
|
|
32
|
+
input(value: import("@entro314labs/entro-auth-core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
displayUsername: {
|
|
36
|
+
type: "string";
|
|
37
|
+
required: false;
|
|
38
|
+
transform: {
|
|
39
|
+
input(value: import("@entro314labs/entro-auth-core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type UsernameSchema = ReturnType<typeof getSchema<true>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/plugins/username/schema.ts
|
|
2
|
+
const getSchema = (normalizer, includeDisplayUsername = true) => {
|
|
3
|
+
const fields = {
|
|
4
|
+
username: {
|
|
5
|
+
type: "string",
|
|
6
|
+
required: false,
|
|
7
|
+
sortable: true,
|
|
8
|
+
unique: true,
|
|
9
|
+
returned: true,
|
|
10
|
+
transform: { input(value) {
|
|
11
|
+
return typeof value !== "string" ? value : normalizer.username(value);
|
|
12
|
+
} }
|
|
13
|
+
},
|
|
14
|
+
displayUsername: {
|
|
15
|
+
type: "string",
|
|
16
|
+
required: false,
|
|
17
|
+
transform: { input(value) {
|
|
18
|
+
return typeof value !== "string" ? value : normalizer.displayUsername(value);
|
|
19
|
+
} }
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
return { user: { fields: includeDisplayUsername ? fields : { username: fields.username } } };
|
|
23
|
+
};
|
|
24
|
+
export { getSchema };
|