@sirketio/auth 0.0.1
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/dist/_virtual/_rolldown/runtime.mjs +36 -0
- package/dist/adapter/index.d.mts +4 -0
- package/dist/adapter/index.mjs +7 -0
- package/dist/api/index.d.mts +3872 -0
- package/dist/api/index.mjs +206 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/api/middlewares/index.d.mts +1 -0
- package/dist/api/middlewares/index.mjs +3 -0
- package/dist/api/middlewares/origin-check.d.mts +18 -0
- package/dist/api/middlewares/origin-check.mjs +140 -0
- package/dist/api/middlewares/origin-check.mjs.map +1 -0
- package/dist/api/rate-limiter/index.mjs +204 -0
- package/dist/api/rate-limiter/index.mjs.map +1 -0
- package/dist/api/routes/account.d.mts +410 -0
- package/dist/api/routes/account.mjs +493 -0
- package/dist/api/routes/account.mjs.map +1 -0
- package/dist/api/routes/callback.d.mts +31 -0
- package/dist/api/routes/callback.mjs +179 -0
- package/dist/api/routes/callback.mjs.map +1 -0
- package/dist/api/routes/email-verification.d.mts +161 -0
- package/dist/api/routes/email-verification.mjs +299 -0
- package/dist/api/routes/email-verification.mjs.map +1 -0
- package/dist/api/routes/error.d.mts +28 -0
- package/dist/api/routes/error.mjs +386 -0
- package/dist/api/routes/error.mjs.map +1 -0
- package/dist/api/routes/index.d.mts +11 -0
- package/dist/api/routes/index.mjs +13 -0
- package/dist/api/routes/ok.d.mts +36 -0
- package/dist/api/routes/ok.mjs +30 -0
- package/dist/api/routes/ok.mjs.map +1 -0
- package/dist/api/routes/password.d.mts +182 -0
- package/dist/api/routes/password.mjs +198 -0
- package/dist/api/routes/password.mjs.map +1 -0
- package/dist/api/routes/session.d.mts +415 -0
- package/dist/api/routes/session.mjs +483 -0
- package/dist/api/routes/session.mjs.map +1 -0
- package/dist/api/routes/sign-in.d.mts +171 -0
- package/dist/api/routes/sign-in.mjs +263 -0
- package/dist/api/routes/sign-in.mjs.map +1 -0
- package/dist/api/routes/sign-out.d.mts +36 -0
- package/dist/api/routes/sign-out.mjs +33 -0
- package/dist/api/routes/sign-out.mjs.map +1 -0
- package/dist/api/routes/sign-up.d.mts +160 -0
- package/dist/api/routes/sign-up.mjs +227 -0
- package/dist/api/routes/sign-up.mjs.map +1 -0
- package/dist/api/routes/update-user.d.mts +445 -0
- package/dist/api/routes/update-user.mjs +493 -0
- package/dist/api/routes/update-user.mjs.map +1 -0
- package/dist/api/state/oauth.d.mts +18 -0
- package/dist/api/state/oauth.mjs +8 -0
- package/dist/api/state/oauth.mjs.map +1 -0
- package/dist/api/state/should-session-refresh.d.mts +13 -0
- package/dist/api/state/should-session-refresh.mjs +16 -0
- package/dist/api/state/should-session-refresh.mjs.map +1 -0
- package/dist/api/to-auth-endpoints.mjs +197 -0
- package/dist/api/to-auth-endpoints.mjs.map +1 -0
- package/dist/auth/base.mjs +45 -0
- package/dist/auth/base.mjs.map +1 -0
- package/dist/auth/minimal.d.mts +12 -0
- package/dist/auth/minimal.mjs +14 -0
- package/dist/auth/minimal.mjs.map +1 -0
- package/dist/auth/trusted-origins.mjs +31 -0
- package/dist/auth/trusted-origins.mjs.map +1 -0
- package/dist/client/broadcast-channel.d.mts +20 -0
- package/dist/client/broadcast-channel.mjs +46 -0
- package/dist/client/broadcast-channel.mjs.map +1 -0
- package/dist/client/config.mjs +90 -0
- package/dist/client/config.mjs.map +1 -0
- package/dist/client/fetch-plugins.mjs +18 -0
- package/dist/client/fetch-plugins.mjs.map +1 -0
- package/dist/client/focus-manager.d.mts +11 -0
- package/dist/client/focus-manager.mjs +32 -0
- package/dist/client/focus-manager.mjs.map +1 -0
- package/dist/client/index.d.mts +33 -0
- package/dist/client/index.mjs +21 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/client/online-manager.d.mts +12 -0
- package/dist/client/online-manager.mjs +35 -0
- package/dist/client/online-manager.mjs.map +1 -0
- package/dist/client/parser.mjs +73 -0
- package/dist/client/parser.mjs.map +1 -0
- package/dist/client/path-to-object.d.mts +65 -0
- package/dist/client/plugins/index.d.mts +53 -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/plugins/infer-plugin.mjs.map +1 -0
- package/dist/client/proxy.mjs +79 -0
- package/dist/client/proxy.mjs.map +1 -0
- package/dist/client/query.d.mts +23 -0
- package/dist/client/query.mjs +98 -0
- package/dist/client/query.mjs.map +1 -0
- package/dist/client/react/index.d.mts +128 -0
- package/dist/client/react/index.mjs +24 -0
- package/dist/client/react/index.mjs.map +1 -0
- package/dist/client/react/react-store.d.mts +47 -0
- package/dist/client/react/react-store.mjs +47 -0
- package/dist/client/react/react-store.mjs.map +1 -0
- package/dist/client/session-atom.mjs +29 -0
- package/dist/client/session-atom.mjs.map +1 -0
- package/dist/client/session-refresh.d.mts +28 -0
- package/dist/client/session-refresh.mjs +140 -0
- package/dist/client/session-refresh.mjs.map +1 -0
- package/dist/client/types.d.mts +41 -0
- package/dist/client/vanilla.d.mts +127 -0
- package/dist/client/vanilla.mjs +20 -0
- package/dist/client/vanilla.mjs.map +1 -0
- package/dist/context/create-context.mjs +211 -0
- package/dist/context/create-context.mjs.map +1 -0
- package/dist/context/helpers.mjs +83 -0
- package/dist/context/helpers.mjs.map +1 -0
- package/dist/context/init.mjs +20 -0
- package/dist/context/init.mjs.map +1 -0
- package/dist/cookies/cookie-utils.d.mts +29 -0
- package/dist/cookies/cookie-utils.mjs +105 -0
- package/dist/cookies/cookie-utils.mjs.map +1 -0
- package/dist/cookies/index.d.mts +121 -0
- package/dist/cookies/index.mjs +261 -0
- package/dist/cookies/index.mjs.map +1 -0
- package/dist/cookies/session-store.d.mts +36 -0
- package/dist/cookies/session-store.mjs +200 -0
- package/dist/cookies/session-store.mjs.map +1 -0
- package/dist/crypto/buffer.d.mts +8 -0
- package/dist/crypto/buffer.mjs +18 -0
- package/dist/crypto/buffer.mjs.map +1 -0
- package/dist/crypto/index.d.mts +27 -0
- package/dist/crypto/index.mjs +38 -0
- package/dist/crypto/index.mjs.map +1 -0
- package/dist/crypto/jwt.d.mts +8 -0
- package/dist/crypto/jwt.mjs +95 -0
- package/dist/crypto/jwt.mjs.map +1 -0
- package/dist/crypto/password.d.mts +12 -0
- package/dist/crypto/password.mjs +36 -0
- package/dist/crypto/password.mjs.map +1 -0
- package/dist/crypto/random.d.mts +5 -0
- package/dist/crypto/random.mjs +8 -0
- package/dist/crypto/random.mjs.map +1 -0
- package/dist/db/adapter-base.d.mts +8 -0
- package/dist/db/adapter-base.mjs +19 -0
- package/dist/db/adapter-base.mjs.map +1 -0
- package/dist/db/field-converter.d.mts +8 -0
- package/dist/db/field-converter.mjs +21 -0
- package/dist/db/field-converter.mjs.map +1 -0
- package/dist/db/field.d.mts +42 -0
- package/dist/db/get-schema.d.mts +11 -0
- package/dist/db/get-schema.mjs +39 -0
- package/dist/db/get-schema.mjs.map +1 -0
- package/dist/db/index.d.mts +18 -0
- package/dist/db/index.mjs +34 -0
- package/dist/db/index.mjs.map +1 -0
- package/dist/db/internal-adapter.d.mts +14 -0
- package/dist/db/internal-adapter.mjs +616 -0
- package/dist/db/internal-adapter.mjs.map +1 -0
- package/dist/db/schema.d.mts +49 -0
- package/dist/db/schema.mjs +118 -0
- package/dist/db/schema.mjs.map +1 -0
- package/dist/db/to-zod.d.mts +36 -0
- package/dist/db/to-zod.mjs +26 -0
- package/dist/db/to-zod.mjs.map +1 -0
- package/dist/db/verification-token-storage.mjs +28 -0
- package/dist/db/verification-token-storage.mjs.map +1 -0
- package/dist/db/with-hooks.d.mts +33 -0
- package/dist/db/with-hooks.mjs +159 -0
- package/dist/db/with-hooks.mjs.map +1 -0
- package/dist/index.d.mts +53 -0
- package/dist/index.mjs +27 -0
- package/dist/integrations/next-js.d.mts +29 -0
- package/dist/integrations/next-js.mjs +85 -0
- package/dist/integrations/next-js.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +5 -0
- package/dist/oauth2/index.mjs +7 -0
- package/dist/oauth2/link-account.d.mts +48 -0
- package/dist/oauth2/link-account.mjs +143 -0
- package/dist/oauth2/link-account.mjs.map +1 -0
- package/dist/oauth2/state.d.mts +26 -0
- package/dist/oauth2/state.mjs +51 -0
- package/dist/oauth2/state.mjs.map +1 -0
- package/dist/oauth2/utils.d.mts +8 -0
- package/dist/oauth2/utils.mjs +31 -0
- package/dist/oauth2/utils.mjs.map +1 -0
- package/dist/plugins/access/access.d.mts +30 -0
- package/dist/plugins/access/access.mjs +46 -0
- package/dist/plugins/access/access.mjs.map +1 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +3 -0
- package/dist/plugins/access/types.d.mts +17 -0
- package/dist/plugins/additional-fields/client.d.mts +96 -0
- package/dist/plugins/additional-fields/client.mjs +11 -0
- package/dist/plugins/additional-fields/client.mjs.map +1 -0
- package/dist/plugins/admin/access/index.d.mts +2 -0
- package/dist/plugins/admin/access/index.mjs +3 -0
- package/dist/plugins/admin/access/statement.d.mts +118 -0
- package/dist/plugins/admin/access/statement.mjs +53 -0
- package/dist/plugins/admin/access/statement.mjs.map +1 -0
- package/dist/plugins/admin/admin.d.mts +911 -0
- package/dist/plugins/admin/admin.mjs +95 -0
- package/dist/plugins/admin/admin.mjs.map +1 -0
- package/dist/plugins/admin/client.d.mts +76 -0
- package/dist/plugins/admin/client.mjs +36 -0
- package/dist/plugins/admin/client.mjs.map +1 -0
- package/dist/plugins/admin/error-codes.d.mts +29 -0
- package/dist/plugins/admin/error-codes.mjs +30 -0
- package/dist/plugins/admin/error-codes.mjs.map +1 -0
- package/dist/plugins/admin/has-permission.mjs +16 -0
- package/dist/plugins/admin/has-permission.mjs.map +1 -0
- package/dist/plugins/admin/index.d.mts +3 -0
- package/dist/plugins/admin/index.mjs +3 -0
- package/dist/plugins/admin/routes.mjs +841 -0
- package/dist/plugins/admin/routes.mjs.map +1 -0
- package/dist/plugins/admin/schema.d.mts +40 -0
- package/dist/plugins/admin/schema.mjs +34 -0
- package/dist/plugins/admin/schema.mjs.map +1 -0
- package/dist/plugins/admin/types.d.mts +89 -0
- package/dist/plugins/api-key/adapter.mjs +468 -0
- package/dist/plugins/api-key/adapter.mjs.map +1 -0
- package/dist/plugins/api-key/client.d.mts +46 -0
- package/dist/plugins/api-key/client.mjs +19 -0
- package/dist/plugins/api-key/client.mjs.map +1 -0
- package/dist/plugins/api-key/error-codes.d.mts +33 -0
- package/dist/plugins/api-key/error-codes.mjs +34 -0
- package/dist/plugins/api-key/error-codes.mjs.map +1 -0
- package/dist/plugins/api-key/index.d.mts +1251 -0
- package/dist/plugins/api-key/index.mjs +134 -0
- package/dist/plugins/api-key/index.mjs.map +1 -0
- package/dist/plugins/api-key/rate-limit.mjs +74 -0
- package/dist/plugins/api-key/rate-limit.mjs.map +1 -0
- package/dist/plugins/api-key/routes/create-api-key.mjs +252 -0
- package/dist/plugins/api-key/routes/create-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs +24 -0
- package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs.map +1 -0
- package/dist/plugins/api-key/routes/delete-api-key.mjs +74 -0
- package/dist/plugins/api-key/routes/delete-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/get-api-key.mjs +158 -0
- package/dist/plugins/api-key/routes/get-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/index.mjs +71 -0
- package/dist/plugins/api-key/routes/index.mjs.map +1 -0
- package/dist/plugins/api-key/routes/list-api-keys.mjs +194 -0
- package/dist/plugins/api-key/routes/list-api-keys.mjs.map +1 -0
- package/dist/plugins/api-key/routes/update-api-key.mjs +248 -0
- package/dist/plugins/api-key/routes/update-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/verify-api-key.mjs +224 -0
- package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/schema.d.mts +199 -0
- package/dist/plugins/api-key/schema.mjs +130 -0
- package/dist/plugins/api-key/schema.mjs.map +1 -0
- package/dist/plugins/api-key/types.d.mts +346 -0
- package/dist/plugins/bearer/index.d.mts +45 -0
- package/dist/plugins/bearer/index.mjs +66 -0
- package/dist/plugins/bearer/index.mjs.map +1 -0
- package/dist/plugins/captcha/constants.d.mts +10 -0
- package/dist/plugins/captcha/constants.mjs +22 -0
- package/dist/plugins/captcha/constants.mjs.map +1 -0
- package/dist/plugins/captcha/error-codes.mjs +16 -0
- package/dist/plugins/captcha/error-codes.mjs.map +1 -0
- package/dist/plugins/captcha/index.d.mts +21 -0
- package/dist/plugins/captcha/index.mjs +62 -0
- package/dist/plugins/captcha/index.mjs.map +1 -0
- package/dist/plugins/captcha/types.d.mts +28 -0
- package/dist/plugins/captcha/utils.mjs +11 -0
- package/dist/plugins/captcha/utils.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs +28 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +26 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +30 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +28 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/index.mjs +6 -0
- package/dist/plugins/custom-session/client.d.mts +17 -0
- package/dist/plugins/custom-session/client.mjs +11 -0
- package/dist/plugins/custom-session/client.mjs.map +1 -0
- package/dist/plugins/custom-session/index.d.mts +72 -0
- package/dist/plugins/custom-session/index.mjs +78 -0
- package/dist/plugins/custom-session/index.mjs.map +1 -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/client.mjs.map +1 -0
- package/dist/plugins/device-authorization/error-codes.mjs +21 -0
- package/dist/plugins/device-authorization/error-codes.mjs.map +1 -0
- package/dist/plugins/device-authorization/index.d.mts +424 -0
- package/dist/plugins/device-authorization/index.mjs +50 -0
- package/dist/plugins/device-authorization/index.mjs.map +1 -0
- package/dist/plugins/device-authorization/routes.mjs +510 -0
- package/dist/plugins/device-authorization/routes.mjs.map +1 -0
- package/dist/plugins/device-authorization/schema.mjs +57 -0
- package/dist/plugins/device-authorization/schema.mjs.map +1 -0
- package/dist/plugins/email-otp/client.d.mts +21 -0
- package/dist/plugins/email-otp/client.mjs +18 -0
- package/dist/plugins/email-otp/client.mjs.map +1 -0
- package/dist/plugins/email-otp/error-codes.d.mts +11 -0
- package/dist/plugins/email-otp/error-codes.mjs +12 -0
- package/dist/plugins/email-otp/error-codes.mjs.map +1 -0
- package/dist/plugins/email-otp/index.d.mts +428 -0
- package/dist/plugins/email-otp/index.mjs +130 -0
- package/dist/plugins/email-otp/index.mjs.map +1 -0
- package/dist/plugins/email-otp/otp-token.mjs +29 -0
- package/dist/plugins/email-otp/otp-token.mjs.map +1 -0
- package/dist/plugins/email-otp/routes.mjs +631 -0
- package/dist/plugins/email-otp/routes.mjs.map +1 -0
- package/dist/plugins/email-otp/types.d.mts +86 -0
- package/dist/plugins/email-otp/utils.mjs +17 -0
- package/dist/plugins/email-otp/utils.mjs.map +1 -0
- package/dist/plugins/generic-oauth/client.d.mts +33 -0
- package/dist/plugins/generic-oauth/client.mjs +14 -0
- package/dist/plugins/generic-oauth/client.mjs.map +1 -0
- package/dist/plugins/generic-oauth/error-codes.d.mts +16 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +17 -0
- package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/index.d.mts +201 -0
- package/dist/plugins/generic-oauth/index.mjs +145 -0
- package/dist/plugins/generic-oauth/index.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs +60 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +60 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/index.d.mts +9 -0
- package/dist/plugins/generic-oauth/providers/index.mjs +11 -0
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/line.d.mts +55 -0
- package/dist/plugins/generic-oauth/providers/line.mjs +91 -0
- package/dist/plugins/generic-oauth/providers/line.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +66 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/okta.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +30 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs +59 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/slack.d.mts +30 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs +61 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs.map +1 -0
- package/dist/plugins/generic-oauth/routes.mjs +411 -0
- package/dist/plugins/generic-oauth/routes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/types.d.mts +159 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +46 -0
- package/dist/plugins/haveibeenpwned/index.mjs +57 -0
- package/dist/plugins/haveibeenpwned/index.mjs.map +1 -0
- package/dist/plugins/index.d.mts +65 -0
- package/dist/plugins/index.mjs +48 -0
- package/dist/plugins/jwt/adapter.mjs +27 -0
- package/dist/plugins/jwt/adapter.mjs.map +1 -0
- package/dist/plugins/jwt/client.d.mts +40 -0
- package/dist/plugins/jwt/client.mjs +19 -0
- package/dist/plugins/jwt/client.mjs.map +1 -0
- package/dist/plugins/jwt/index.d.mts +224 -0
- package/dist/plugins/jwt/index.mjs +202 -0
- package/dist/plugins/jwt/index.mjs.map +1 -0
- package/dist/plugins/jwt/schema.d.mts +26 -0
- package/dist/plugins/jwt/schema.mjs +23 -0
- package/dist/plugins/jwt/schema.mjs.map +1 -0
- package/dist/plugins/jwt/sign.d.mts +57 -0
- package/dist/plugins/jwt/sign.mjs +66 -0
- package/dist/plugins/jwt/sign.mjs.map +1 -0
- package/dist/plugins/jwt/types.d.mts +194 -0
- package/dist/plugins/jwt/utils.d.mts +42 -0
- package/dist/plugins/jwt/utils.mjs +64 -0
- package/dist/plugins/jwt/utils.mjs.map +1 -0
- package/dist/plugins/jwt/verify.d.mts +12 -0
- package/dist/plugins/jwt/verify.mjs +46 -0
- package/dist/plugins/jwt/verify.mjs.map +1 -0
- package/dist/plugins/last-login-method/client.d.mts +38 -0
- package/dist/plugins/last-login-method/client.mjs +32 -0
- package/dist/plugins/last-login-method/client.mjs.map +1 -0
- package/dist/plugins/last-login-method/index.d.mts +118 -0
- package/dist/plugins/last-login-method/index.mjs +76 -0
- package/dist/plugins/last-login-method/index.mjs.map +1 -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/client.mjs.map +1 -0
- package/dist/plugins/magic-link/index.d.mts +193 -0
- package/dist/plugins/magic-link/index.mjs +177 -0
- package/dist/plugins/magic-link/index.mjs.map +1 -0
- package/dist/plugins/magic-link/utils.mjs +12 -0
- package/dist/plugins/magic-link/utils.mjs.map +1 -0
- package/dist/plugins/mcp/authorize.mjs +133 -0
- package/dist/plugins/mcp/authorize.mjs.map +1 -0
- package/dist/plugins/mcp/index.d.mts +458 -0
- package/dist/plugins/mcp/index.mjs +717 -0
- package/dist/plugins/mcp/index.mjs.map +1 -0
- package/dist/plugins/multi-session/client.d.mts +19 -0
- package/dist/plugins/multi-session/client.mjs +20 -0
- package/dist/plugins/multi-session/client.mjs.map +1 -0
- package/dist/plugins/multi-session/error-codes.d.mts +9 -0
- package/dist/plugins/multi-session/error-codes.mjs +8 -0
- package/dist/plugins/multi-session/error-codes.mjs.map +1 -0
- package/dist/plugins/multi-session/index.d.mts +235 -0
- package/dist/plugins/multi-session/index.mjs +172 -0
- package/dist/plugins/multi-session/index.mjs.map +1 -0
- package/dist/plugins/oauth-proxy/index.d.mts +97 -0
- package/dist/plugins/oauth-proxy/index.mjs +305 -0
- package/dist/plugins/oauth-proxy/index.mjs.map +1 -0
- package/dist/plugins/oauth-proxy/utils.mjs +51 -0
- package/dist/plugins/oauth-proxy/utils.mjs.map +1 -0
- package/dist/plugins/oidc-provider/authorize.mjs +194 -0
- package/dist/plugins/oidc-provider/authorize.mjs.map +1 -0
- package/dist/plugins/oidc-provider/client.d.mts +12 -0
- package/dist/plugins/oidc-provider/client.mjs +11 -0
- package/dist/plugins/oidc-provider/client.mjs.map +1 -0
- package/dist/plugins/oidc-provider/error.mjs +17 -0
- package/dist/plugins/oidc-provider/error.mjs.map +1 -0
- package/dist/plugins/oidc-provider/index.d.mts +702 -0
- package/dist/plugins/oidc-provider/index.mjs +1093 -0
- package/dist/plugins/oidc-provider/index.mjs.map +1 -0
- package/dist/plugins/oidc-provider/schema.d.mts +160 -0
- package/dist/plugins/oidc-provider/schema.mjs +132 -0
- package/dist/plugins/oidc-provider/schema.mjs.map +1 -0
- package/dist/plugins/oidc-provider/types.d.mts +517 -0
- package/dist/plugins/oidc-provider/utils/prompt.mjs +19 -0
- package/dist/plugins/oidc-provider/utils/prompt.mjs.map +1 -0
- package/dist/plugins/oidc-provider/utils.mjs +15 -0
- package/dist/plugins/oidc-provider/utils.mjs.map +1 -0
- package/dist/plugins/one-tap/client.d.mts +174 -0
- package/dist/plugins/one-tap/client.mjs +188 -0
- package/dist/plugins/one-tap/client.mjs.map +1 -0
- package/dist/plugins/one-tap/index.d.mts +83 -0
- package/dist/plugins/one-tap/index.mjs +95 -0
- package/dist/plugins/one-tap/index.mjs.map +1 -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/client.mjs.map +1 -0
- package/dist/plugins/one-time-token/index.d.mts +133 -0
- package/dist/plugins/one-time-token/index.mjs +82 -0
- package/dist/plugins/one-time-token/index.mjs.map +1 -0
- package/dist/plugins/one-time-token/utils.mjs +12 -0
- package/dist/plugins/one-time-token/utils.mjs.map +1 -0
- package/dist/plugins/open-api/generator.d.mts +115 -0
- package/dist/plugins/open-api/generator.mjs +315 -0
- package/dist/plugins/open-api/generator.mjs.map +1 -0
- package/dist/plugins/open-api/index.d.mts +97 -0
- package/dist/plugins/open-api/index.mjs +67 -0
- package/dist/plugins/open-api/index.mjs.map +1 -0
- package/dist/plugins/open-api/logo.mjs +15 -0
- package/dist/plugins/open-api/logo.mjs.map +1 -0
- package/dist/plugins/organization/access/index.d.mts +2 -0
- package/dist/plugins/organization/access/index.mjs +3 -0
- package/dist/plugins/organization/access/statement.d.mts +249 -0
- package/dist/plugins/organization/access/statement.mjs +81 -0
- package/dist/plugins/organization/access/statement.mjs.map +1 -0
- package/dist/plugins/organization/adapter.d.mts +792 -0
- package/dist/plugins/organization/adapter.mjs +624 -0
- package/dist/plugins/organization/adapter.mjs.map +1 -0
- package/dist/plugins/organization/call.mjs +19 -0
- package/dist/plugins/organization/call.mjs.map +1 -0
- package/dist/plugins/organization/client.d.mts +372 -0
- package/dist/plugins/organization/client.mjs +95 -0
- package/dist/plugins/organization/client.mjs.map +1 -0
- package/dist/plugins/organization/error-codes.d.mts +65 -0
- package/dist/plugins/organization/error-codes.mjs +66 -0
- package/dist/plugins/organization/error-codes.mjs.map +1 -0
- package/dist/plugins/organization/has-permission.mjs +35 -0
- package/dist/plugins/organization/has-permission.mjs.map +1 -0
- package/dist/plugins/organization/index.d.mts +5 -0
- package/dist/plugins/organization/index.mjs +4 -0
- package/dist/plugins/organization/organization.d.mts +394 -0
- package/dist/plugins/organization/organization.mjs +428 -0
- package/dist/plugins/organization/organization.mjs.map +1 -0
- package/dist/plugins/organization/permission.d.mts +17 -0
- package/dist/plugins/organization/permission.mjs +16 -0
- package/dist/plugins/organization/permission.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-access-control.d.mts +394 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +678 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +1031 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +551 -0
- package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +940 -0
- package/dist/plugins/organization/routes/crud-members.mjs +466 -0
- package/dist/plugins/organization/routes/crud-members.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +708 -0
- package/dist/plugins/organization/routes/crud-org.mjs +423 -0
- package/dist/plugins/organization/routes/crud-org.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +1071 -0
- package/dist/plugins/organization/routes/crud-team.mjs +676 -0
- package/dist/plugins/organization/routes/crud-team.mjs.map +1 -0
- package/dist/plugins/organization/schema.d.mts +376 -0
- package/dist/plugins/organization/schema.mjs +68 -0
- package/dist/plugins/organization/schema.mjs.map +1 -0
- package/dist/plugins/organization/types.d.mts +677 -0
- package/dist/plugins/phone-number/client.d.mts +31 -0
- package/dist/plugins/phone-number/client.mjs +20 -0
- package/dist/plugins/phone-number/client.mjs.map +1 -0
- package/dist/plugins/phone-number/error-codes.d.mts +20 -0
- package/dist/plugins/phone-number/error-codes.mjs +21 -0
- package/dist/plugins/phone-number/error-codes.mjs.map +1 -0
- package/dist/plugins/phone-number/index.d.mts +318 -0
- package/dist/plugins/phone-number/index.mjs +49 -0
- package/dist/plugins/phone-number/index.mjs.map +1 -0
- package/dist/plugins/phone-number/routes.mjs +472 -0
- package/dist/plugins/phone-number/routes.mjs.map +1 -0
- package/dist/plugins/phone-number/schema.d.mts +23 -0
- package/dist/plugins/phone-number/schema.mjs +20 -0
- package/dist/plugins/phone-number/schema.mjs.map +1 -0
- package/dist/plugins/phone-number/types.d.mts +118 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +279 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs +277 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs.map +1 -0
- package/dist/plugins/two-factor/client.d.mts +55 -0
- package/dist/plugins/two-factor/client.mjs +37 -0
- package/dist/plugins/two-factor/client.mjs.map +1 -0
- package/dist/plugins/two-factor/constant.mjs +8 -0
- package/dist/plugins/two-factor/constant.mjs.map +1 -0
- package/dist/plugins/two-factor/error-code.d.mts +17 -0
- package/dist/plugins/two-factor/error-code.mjs +18 -0
- package/dist/plugins/two-factor/error-code.mjs.map +1 -0
- package/dist/plugins/two-factor/index.d.mts +670 -0
- package/dist/plugins/two-factor/index.mjs +228 -0
- package/dist/plugins/two-factor/index.mjs.map +1 -0
- package/dist/plugins/two-factor/otp/index.d.mts +216 -0
- package/dist/plugins/two-factor/otp/index.mjs +199 -0
- package/dist/plugins/two-factor/otp/index.mjs.map +1 -0
- package/dist/plugins/two-factor/schema.d.mts +41 -0
- package/dist/plugins/two-factor/schema.mjs +36 -0
- package/dist/plugins/two-factor/schema.mjs.map +1 -0
- package/dist/plugins/two-factor/totp/index.d.mts +210 -0
- package/dist/plugins/two-factor/totp/index.mjs +157 -0
- package/dist/plugins/two-factor/totp/index.mjs.map +1 -0
- package/dist/plugins/two-factor/types.d.mts +73 -0
- package/dist/plugins/two-factor/utils.mjs +12 -0
- package/dist/plugins/two-factor/utils.mjs.map +1 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs +85 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs.map +1 -0
- package/dist/plugins/username/client.d.mts +26 -0
- package/dist/plugins/username/client.mjs +18 -0
- package/dist/plugins/username/client.mjs.map +1 -0
- package/dist/plugins/username/error-codes.d.mts +16 -0
- package/dist/plugins/username/error-codes.mjs +17 -0
- package/dist/plugins/username/error-codes.mjs.map +1 -0
- package/dist/plugins/username/index.d.mts +251 -0
- package/dist/plugins/username/index.mjs +234 -0
- package/dist/plugins/username/index.mjs.map +1 -0
- package/dist/plugins/username/schema.d.mts +33 -0
- package/dist/plugins/username/schema.mjs +26 -0
- package/dist/plugins/username/schema.mjs.map +1 -0
- package/dist/providers/index.d.mts +1 -0
- package/dist/providers/index.mjs +3 -0
- package/dist/state.d.mts +42 -0
- package/dist/state.mjs +107 -0
- package/dist/state.mjs.map +1 -0
- package/dist/types/adapter.d.mts +2 -0
- package/dist/types/api.d.mts +29 -0
- package/dist/types/auth.d.mts +29 -0
- package/dist/types/helper.d.mts +10 -0
- package/dist/types/index.d.mts +11 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +11 -0
- package/dist/types/plugins.d.mts +20 -0
- package/dist/utils/boolean.mjs +8 -0
- package/dist/utils/boolean.mjs.map +1 -0
- package/dist/utils/constants.mjs +6 -0
- package/dist/utils/constants.mjs.map +1 -0
- package/dist/utils/date.mjs +8 -0
- package/dist/utils/date.mjs.map +1 -0
- package/dist/utils/get-request-ip.d.mts +7 -0
- package/dist/utils/get-request-ip.mjs +23 -0
- package/dist/utils/get-request-ip.mjs.map +1 -0
- package/dist/utils/hide-metadata.d.mts +7 -0
- package/dist/utils/hide-metadata.mjs +6 -0
- package/dist/utils/hide-metadata.mjs.map +1 -0
- package/dist/utils/index.d.mts +4 -0
- package/dist/utils/index.mjs +6 -0
- package/dist/utils/is-api-error.d.mts +7 -0
- package/dist/utils/is-api-error.mjs +11 -0
- package/dist/utils/is-api-error.mjs.map +1 -0
- package/dist/utils/is-atom.mjs +8 -0
- package/dist/utils/is-atom.mjs.map +1 -0
- package/dist/utils/is-promise.mjs +8 -0
- package/dist/utils/is-promise.mjs.map +1 -0
- package/dist/utils/middleware-response.mjs +9 -0
- package/dist/utils/middleware-response.mjs.map +1 -0
- package/dist/utils/password.mjs +26 -0
- package/dist/utils/password.mjs.map +1 -0
- package/dist/utils/plugin-helper.mjs +17 -0
- package/dist/utils/plugin-helper.mjs.map +1 -0
- package/dist/utils/shim.mjs +24 -0
- package/dist/utils/shim.mjs.map +1 -0
- package/dist/utils/time.d.mts +49 -0
- package/dist/utils/time.mjs +100 -0
- package/dist/utils/time.mjs.map +1 -0
- package/dist/utils/url.d.mts +8 -0
- package/dist/utils/url.mjs +92 -0
- package/dist/utils/url.mjs.map +1 -0
- package/dist/utils/wildcard.mjs +108 -0
- package/dist/utils/wildcard.mjs.map +1 -0
- package/package.json +428 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { User } from "../../types/models.mjs";
|
|
2
|
+
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
3
|
+
import "../../types/index.mjs";
|
|
4
|
+
import { schema } from "./schema.mjs";
|
|
5
|
+
import { Awaitable, GenericEndpointContext } from "@better-auth/core";
|
|
6
|
+
|
|
7
|
+
//#region src/plugins/phone-number/types.d.ts
|
|
8
|
+
interface UserWithPhoneNumber extends User {
|
|
9
|
+
phoneNumber: string;
|
|
10
|
+
phoneNumberVerified: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface PhoneNumberOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Length of the OTP code
|
|
15
|
+
* @default 6
|
|
16
|
+
*/
|
|
17
|
+
otpLength?: number | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Send OTP code to the user
|
|
20
|
+
*
|
|
21
|
+
* @param phoneNumber
|
|
22
|
+
* @param code
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
sendOTP: (data: {
|
|
26
|
+
phoneNumber: string;
|
|
27
|
+
code: string;
|
|
28
|
+
}, ctx?: GenericEndpointContext | undefined) => Awaitable<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Custom OTP verification function
|
|
31
|
+
*
|
|
32
|
+
* If provided, this function will be called instead of the internal verification logic.
|
|
33
|
+
* This is useful when using SMS providers that handle their own OTP generation and verification.
|
|
34
|
+
*
|
|
35
|
+
* @param data - Contains phone number and OTP code
|
|
36
|
+
* @param request - The request object
|
|
37
|
+
* @returns true if OTP is valid, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
verifyOTP?: ((data: {
|
|
40
|
+
phoneNumber: string;
|
|
41
|
+
code: string;
|
|
42
|
+
}, ctx?: GenericEndpointContext) => Awaitable<boolean>) | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* a callback to send otp on user requesting to reset their password
|
|
45
|
+
*
|
|
46
|
+
* @param data - contains phone number and code
|
|
47
|
+
* @param request - the request object
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
sendPasswordResetOTP?: ((data: {
|
|
51
|
+
phoneNumber: string;
|
|
52
|
+
code: string;
|
|
53
|
+
}, ctx?: GenericEndpointContext) => Awaitable<void>) | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Expiry time of the OTP code in seconds
|
|
56
|
+
* @default 300
|
|
57
|
+
*/
|
|
58
|
+
expiresIn?: number | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Function to validate phone number
|
|
61
|
+
*
|
|
62
|
+
* by default any string is accepted
|
|
63
|
+
*/
|
|
64
|
+
phoneNumberValidator?: ((phoneNumber: string) => Awaitable<boolean>) | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Require a phone number verification before signing in
|
|
67
|
+
*
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
requireVerification?: boolean | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Callback when phone number is verified
|
|
73
|
+
*/
|
|
74
|
+
callbackOnVerification?: ((data: {
|
|
75
|
+
phoneNumber: string;
|
|
76
|
+
user: UserWithPhoneNumber;
|
|
77
|
+
}, ctx?: GenericEndpointContext) => Awaitable<void>) | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Sign up user after phone number verification
|
|
80
|
+
*
|
|
81
|
+
* the user will be signed up with the temporary email
|
|
82
|
+
* and the phone number will be updated after verification
|
|
83
|
+
*/
|
|
84
|
+
signUpOnVerification?: {
|
|
85
|
+
/**
|
|
86
|
+
* When a user signs up, a temporary email will be need to be created
|
|
87
|
+
* to sign up the user. This function should return a temporary email
|
|
88
|
+
* for the user given the phone number
|
|
89
|
+
*
|
|
90
|
+
* @param phoneNumber
|
|
91
|
+
* @returns string (temporary email)
|
|
92
|
+
*/
|
|
93
|
+
getTempEmail: (phoneNumber: string) => string;
|
|
94
|
+
/**
|
|
95
|
+
* When a user signs up, a temporary name will be need to be created
|
|
96
|
+
* to sign up the user. This function should return a temporary name
|
|
97
|
+
* for the user given the phone number
|
|
98
|
+
*
|
|
99
|
+
* @param phoneNumber
|
|
100
|
+
* @returns string (temporary name)
|
|
101
|
+
*
|
|
102
|
+
* @default phoneNumber - the phone number will be used as the name
|
|
103
|
+
*/
|
|
104
|
+
getTempName?: (phoneNumber: string) => string;
|
|
105
|
+
} | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Custom schema for the admin plugin
|
|
108
|
+
*/
|
|
109
|
+
schema?: InferOptionSchema<typeof schema> | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Allowed attempts for the OTP code
|
|
112
|
+
* @default 3
|
|
113
|
+
*/
|
|
114
|
+
allowedAttempts?: number | undefined;
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { PhoneNumberOptions, UserWithPhoneNumber };
|
|
118
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { UserWithTwoFactor } from "../types.mjs";
|
|
2
|
+
import * as better_call0 from "better-call";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/two-factor/backup-codes/index.d.ts
|
|
6
|
+
interface BackupCodeOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The amount of backup codes to generate
|
|
9
|
+
*
|
|
10
|
+
* @default 10
|
|
11
|
+
*/
|
|
12
|
+
amount?: number | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The length of the backup codes
|
|
15
|
+
*
|
|
16
|
+
* @default 10
|
|
17
|
+
*/
|
|
18
|
+
length?: number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* An optional custom function to generate backup codes
|
|
21
|
+
*/
|
|
22
|
+
customBackupCodesGenerate?: (() => string[]) | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* How to store the backup codes in the database, whether encrypted or plain.
|
|
25
|
+
*/
|
|
26
|
+
storeBackupCodes?: ("plain" | "encrypted" | {
|
|
27
|
+
encrypt: (token: string) => Promise<string>;
|
|
28
|
+
decrypt: (token: string) => Promise<string>;
|
|
29
|
+
}) | undefined;
|
|
30
|
+
}
|
|
31
|
+
declare function generateBackupCodes(secret: string, options?: BackupCodeOptions | undefined): Promise<{
|
|
32
|
+
backupCodes: string[];
|
|
33
|
+
encryptedBackupCodes: string;
|
|
34
|
+
}>;
|
|
35
|
+
declare function verifyBackupCode(data: {
|
|
36
|
+
backupCodes: string;
|
|
37
|
+
code: string;
|
|
38
|
+
}, key: string, options?: BackupCodeOptions | undefined): Promise<{
|
|
39
|
+
status: boolean;
|
|
40
|
+
updated: null;
|
|
41
|
+
} | {
|
|
42
|
+
status: boolean;
|
|
43
|
+
updated: string[];
|
|
44
|
+
}>;
|
|
45
|
+
declare function getBackupCodes(backupCodes: string, key: string, options?: BackupCodeOptions | undefined): Promise<string[] | null>;
|
|
46
|
+
declare const backupCode2fa: (opts: BackupCodeOptions) => {
|
|
47
|
+
id: "backup_code";
|
|
48
|
+
endpoints: {
|
|
49
|
+
/**
|
|
50
|
+
* ### Endpoint
|
|
51
|
+
*
|
|
52
|
+
* POST `/two-factor/verify-backup-code`
|
|
53
|
+
*
|
|
54
|
+
* ### API Methods
|
|
55
|
+
*
|
|
56
|
+
* **server:**
|
|
57
|
+
* `auth.api.verifyBackupCode`
|
|
58
|
+
*
|
|
59
|
+
* **client:**
|
|
60
|
+
* `authClient.twoFactor.verifyBackupCode`
|
|
61
|
+
*
|
|
62
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-verify-backup-code)
|
|
63
|
+
*/
|
|
64
|
+
verifyBackupCode: better_call0.StrictEndpoint<"/two-factor/verify-backup-code", {
|
|
65
|
+
method: "POST";
|
|
66
|
+
body: z.ZodObject<{
|
|
67
|
+
code: z.ZodString;
|
|
68
|
+
disableSession: z.ZodOptional<z.ZodBoolean>;
|
|
69
|
+
trustDevice: z.ZodOptional<z.ZodBoolean>;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
metadata: {
|
|
72
|
+
openapi: {
|
|
73
|
+
description: string;
|
|
74
|
+
responses: {
|
|
75
|
+
"200": {
|
|
76
|
+
description: string;
|
|
77
|
+
content: {
|
|
78
|
+
"application/json": {
|
|
79
|
+
schema: {
|
|
80
|
+
type: "object";
|
|
81
|
+
properties: {
|
|
82
|
+
user: {
|
|
83
|
+
type: string;
|
|
84
|
+
properties: {
|
|
85
|
+
id: {
|
|
86
|
+
type: string;
|
|
87
|
+
description: string;
|
|
88
|
+
};
|
|
89
|
+
email: {
|
|
90
|
+
type: string;
|
|
91
|
+
format: string;
|
|
92
|
+
nullable: boolean;
|
|
93
|
+
description: string;
|
|
94
|
+
};
|
|
95
|
+
emailVerified: {
|
|
96
|
+
type: string;
|
|
97
|
+
nullable: boolean;
|
|
98
|
+
description: string;
|
|
99
|
+
};
|
|
100
|
+
name: {
|
|
101
|
+
type: string;
|
|
102
|
+
nullable: boolean;
|
|
103
|
+
description: string;
|
|
104
|
+
};
|
|
105
|
+
image: {
|
|
106
|
+
type: string;
|
|
107
|
+
format: string;
|
|
108
|
+
nullable: boolean;
|
|
109
|
+
description: string;
|
|
110
|
+
};
|
|
111
|
+
twoFactorEnabled: {
|
|
112
|
+
type: string;
|
|
113
|
+
description: string;
|
|
114
|
+
};
|
|
115
|
+
createdAt: {
|
|
116
|
+
type: string;
|
|
117
|
+
format: string;
|
|
118
|
+
description: string;
|
|
119
|
+
};
|
|
120
|
+
updatedAt: {
|
|
121
|
+
type: string;
|
|
122
|
+
format: string;
|
|
123
|
+
description: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
required: string[];
|
|
127
|
+
description: string;
|
|
128
|
+
};
|
|
129
|
+
session: {
|
|
130
|
+
type: string;
|
|
131
|
+
properties: {
|
|
132
|
+
token: {
|
|
133
|
+
type: string;
|
|
134
|
+
description: string;
|
|
135
|
+
};
|
|
136
|
+
userId: {
|
|
137
|
+
type: string;
|
|
138
|
+
description: string;
|
|
139
|
+
};
|
|
140
|
+
createdAt: {
|
|
141
|
+
type: string;
|
|
142
|
+
format: string;
|
|
143
|
+
description: string;
|
|
144
|
+
};
|
|
145
|
+
expiresAt: {
|
|
146
|
+
type: string;
|
|
147
|
+
format: string;
|
|
148
|
+
description: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
required: string[];
|
|
152
|
+
description: string;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
required: string[];
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
}, {
|
|
164
|
+
token: string | undefined;
|
|
165
|
+
user: (Record<string, any> & {
|
|
166
|
+
id: string;
|
|
167
|
+
createdAt: Date;
|
|
168
|
+
updatedAt: Date;
|
|
169
|
+
email: string;
|
|
170
|
+
emailVerified: boolean;
|
|
171
|
+
name: string;
|
|
172
|
+
image?: string | null | undefined;
|
|
173
|
+
}) | UserWithTwoFactor;
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* ### Endpoint
|
|
177
|
+
*
|
|
178
|
+
* POST `/two-factor/generate-backup-codes`
|
|
179
|
+
*
|
|
180
|
+
* ### API Methods
|
|
181
|
+
*
|
|
182
|
+
* **server:**
|
|
183
|
+
* `auth.api.generateBackupCodes`
|
|
184
|
+
*
|
|
185
|
+
* **client:**
|
|
186
|
+
* `authClient.twoFactor.generateBackupCodes`
|
|
187
|
+
*
|
|
188
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-generate-backup-codes)
|
|
189
|
+
*/
|
|
190
|
+
generateBackupCodes: better_call0.StrictEndpoint<"/two-factor/generate-backup-codes", {
|
|
191
|
+
method: "POST";
|
|
192
|
+
body: z.ZodObject<{
|
|
193
|
+
password: z.ZodString;
|
|
194
|
+
}, z.core.$strip>;
|
|
195
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
196
|
+
session: {
|
|
197
|
+
session: Record<string, any> & {
|
|
198
|
+
id: string;
|
|
199
|
+
createdAt: Date;
|
|
200
|
+
updatedAt: Date;
|
|
201
|
+
userId: string;
|
|
202
|
+
expiresAt: Date;
|
|
203
|
+
token: string;
|
|
204
|
+
ipAddress?: string | null | undefined;
|
|
205
|
+
userAgent?: string | null | undefined;
|
|
206
|
+
};
|
|
207
|
+
user: Record<string, any> & {
|
|
208
|
+
id: string;
|
|
209
|
+
createdAt: Date;
|
|
210
|
+
updatedAt: Date;
|
|
211
|
+
email: string;
|
|
212
|
+
emailVerified: boolean;
|
|
213
|
+
name: string;
|
|
214
|
+
image?: string | null | undefined;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
}>)[];
|
|
218
|
+
metadata: {
|
|
219
|
+
openapi: {
|
|
220
|
+
description: string;
|
|
221
|
+
responses: {
|
|
222
|
+
"200": {
|
|
223
|
+
description: string;
|
|
224
|
+
content: {
|
|
225
|
+
"application/json": {
|
|
226
|
+
schema: {
|
|
227
|
+
type: "object";
|
|
228
|
+
properties: {
|
|
229
|
+
status: {
|
|
230
|
+
type: string;
|
|
231
|
+
description: string;
|
|
232
|
+
enum: boolean[];
|
|
233
|
+
};
|
|
234
|
+
backupCodes: {
|
|
235
|
+
type: string;
|
|
236
|
+
items: {
|
|
237
|
+
type: string;
|
|
238
|
+
};
|
|
239
|
+
description: string;
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
required: string[];
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
}, {
|
|
251
|
+
status: boolean;
|
|
252
|
+
backupCodes: string[];
|
|
253
|
+
}>;
|
|
254
|
+
/**
|
|
255
|
+
* ### Endpoint
|
|
256
|
+
*
|
|
257
|
+
* POST `/two-factor/view-backup-codes`
|
|
258
|
+
*
|
|
259
|
+
* ### API Methods
|
|
260
|
+
*
|
|
261
|
+
* **server:**
|
|
262
|
+
* `auth.api.viewBackupCodes`
|
|
263
|
+
*
|
|
264
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#api-method-two-factor-view-backup-codes)
|
|
265
|
+
*/
|
|
266
|
+
viewBackupCodes: better_call0.StrictEndpoint<string, {
|
|
267
|
+
method: "POST";
|
|
268
|
+
body: z.ZodObject<{
|
|
269
|
+
userId: z.ZodCoercedString<unknown>;
|
|
270
|
+
}, z.core.$strip>;
|
|
271
|
+
}, {
|
|
272
|
+
status: boolean;
|
|
273
|
+
backupCodes: string[];
|
|
274
|
+
}>;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
//#endregion
|
|
278
|
+
export { BackupCodeOptions, backupCode2fa, generateBackupCodes, getBackupCodes, verifyBackupCode };
|
|
279
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { parseUserOutput } from "../../../db/schema.mjs";
|
|
2
|
+
import { generateRandomString } from "../../../crypto/random.mjs";
|
|
3
|
+
import { symmetricDecrypt, symmetricEncrypt } from "../../../crypto/index.mjs";
|
|
4
|
+
import { sessionMiddleware } from "../../../api/routes/session.mjs";
|
|
5
|
+
import "../../../api/index.mjs";
|
|
6
|
+
import { TWO_FACTOR_ERROR_CODES } from "../error-code.mjs";
|
|
7
|
+
import { verifyTwoFactor } from "../verify-two-factor.mjs";
|
|
8
|
+
import { APIError } from "@better-auth/core/error";
|
|
9
|
+
import { safeJSONParse } from "@better-auth/core/utils/json";
|
|
10
|
+
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
11
|
+
import * as z from "zod";
|
|
12
|
+
|
|
13
|
+
//#region src/plugins/two-factor/backup-codes/index.ts
|
|
14
|
+
function generateBackupCodesFn(options) {
|
|
15
|
+
return Array.from({ length: options?.amount ?? 10 }).fill(null).map(() => generateRandomString(options?.length ?? 10, "a-z", "0-9", "A-Z")).map((code) => `${code.slice(0, 5)}-${code.slice(5)}`);
|
|
16
|
+
}
|
|
17
|
+
async function generateBackupCodes(secret, options) {
|
|
18
|
+
const backupCodes = options?.customBackupCodesGenerate ? options.customBackupCodesGenerate() : generateBackupCodesFn(options);
|
|
19
|
+
if (options?.storeBackupCodes === "encrypted") return {
|
|
20
|
+
backupCodes,
|
|
21
|
+
encryptedBackupCodes: await symmetricEncrypt({
|
|
22
|
+
data: JSON.stringify(backupCodes),
|
|
23
|
+
key: secret
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
if (typeof options?.storeBackupCodes === "object" && "encrypt" in options?.storeBackupCodes) return {
|
|
27
|
+
backupCodes,
|
|
28
|
+
encryptedBackupCodes: await options?.storeBackupCodes.encrypt(JSON.stringify(backupCodes))
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
backupCodes,
|
|
32
|
+
encryptedBackupCodes: JSON.stringify(backupCodes)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function verifyBackupCode(data, key, options) {
|
|
36
|
+
const codes = await getBackupCodes(data.backupCodes, key, options);
|
|
37
|
+
if (!codes) return {
|
|
38
|
+
status: false,
|
|
39
|
+
updated: null
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
status: codes.includes(data.code),
|
|
43
|
+
updated: codes.filter((code) => code !== data.code)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function getBackupCodes(backupCodes, key, options) {
|
|
47
|
+
if (options?.storeBackupCodes === "encrypted") return safeJSONParse(await symmetricDecrypt({
|
|
48
|
+
key,
|
|
49
|
+
data: backupCodes
|
|
50
|
+
}));
|
|
51
|
+
if (typeof options?.storeBackupCodes === "object" && "decrypt" in options?.storeBackupCodes) return safeJSONParse(await options?.storeBackupCodes.decrypt(backupCodes));
|
|
52
|
+
return safeJSONParse(backupCodes);
|
|
53
|
+
}
|
|
54
|
+
const verifyBackupCodeBodySchema = z.object({
|
|
55
|
+
code: z.string().meta({ description: `A backup code to verify. Eg: "123456"` }),
|
|
56
|
+
disableSession: z.boolean().meta({ description: "If true, the session cookie will not be set." }).optional(),
|
|
57
|
+
trustDevice: z.boolean().meta({ description: "If true, the device will be trusted for 30 days. It'll be refreshed on every sign in request within this time. Eg: true" }).optional()
|
|
58
|
+
});
|
|
59
|
+
const viewBackupCodesBodySchema = z.object({ userId: z.coerce.string().meta({ description: `The user ID to view all backup codes. Eg: "user-id"` }) });
|
|
60
|
+
const generateBackupCodesBodySchema = z.object({ password: z.string().meta({ description: "The users password." }) });
|
|
61
|
+
const backupCode2fa = (opts) => {
|
|
62
|
+
const twoFactorTable = "twoFactor";
|
|
63
|
+
return {
|
|
64
|
+
id: "backup_code",
|
|
65
|
+
endpoints: {
|
|
66
|
+
verifyBackupCode: createAuthEndpoint("/two-factor/verify-backup-code", {
|
|
67
|
+
method: "POST",
|
|
68
|
+
body: verifyBackupCodeBodySchema,
|
|
69
|
+
metadata: { openapi: {
|
|
70
|
+
description: "Verify a backup code for two-factor authentication",
|
|
71
|
+
responses: { "200": {
|
|
72
|
+
description: "Backup code verified successfully",
|
|
73
|
+
content: { "application/json": { schema: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {
|
|
76
|
+
user: {
|
|
77
|
+
type: "object",
|
|
78
|
+
properties: {
|
|
79
|
+
id: {
|
|
80
|
+
type: "string",
|
|
81
|
+
description: "Unique identifier of the user"
|
|
82
|
+
},
|
|
83
|
+
email: {
|
|
84
|
+
type: "string",
|
|
85
|
+
format: "email",
|
|
86
|
+
nullable: true,
|
|
87
|
+
description: "User's email address"
|
|
88
|
+
},
|
|
89
|
+
emailVerified: {
|
|
90
|
+
type: "boolean",
|
|
91
|
+
nullable: true,
|
|
92
|
+
description: "Whether the email is verified"
|
|
93
|
+
},
|
|
94
|
+
name: {
|
|
95
|
+
type: "string",
|
|
96
|
+
nullable: true,
|
|
97
|
+
description: "User's name"
|
|
98
|
+
},
|
|
99
|
+
image: {
|
|
100
|
+
type: "string",
|
|
101
|
+
format: "uri",
|
|
102
|
+
nullable: true,
|
|
103
|
+
description: "User's profile image URL"
|
|
104
|
+
},
|
|
105
|
+
twoFactorEnabled: {
|
|
106
|
+
type: "boolean",
|
|
107
|
+
description: "Whether two-factor authentication is enabled for the user"
|
|
108
|
+
},
|
|
109
|
+
createdAt: {
|
|
110
|
+
type: "string",
|
|
111
|
+
format: "date-time",
|
|
112
|
+
description: "Timestamp when the user was created"
|
|
113
|
+
},
|
|
114
|
+
updatedAt: {
|
|
115
|
+
type: "string",
|
|
116
|
+
format: "date-time",
|
|
117
|
+
description: "Timestamp when the user was last updated"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
required: [
|
|
121
|
+
"id",
|
|
122
|
+
"twoFactorEnabled",
|
|
123
|
+
"createdAt",
|
|
124
|
+
"updatedAt"
|
|
125
|
+
],
|
|
126
|
+
description: "The authenticated user object with two-factor details"
|
|
127
|
+
},
|
|
128
|
+
session: {
|
|
129
|
+
type: "object",
|
|
130
|
+
properties: {
|
|
131
|
+
token: {
|
|
132
|
+
type: "string",
|
|
133
|
+
description: "Session token"
|
|
134
|
+
},
|
|
135
|
+
userId: {
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "ID of the user associated with the session"
|
|
138
|
+
},
|
|
139
|
+
createdAt: {
|
|
140
|
+
type: "string",
|
|
141
|
+
format: "date-time",
|
|
142
|
+
description: "Timestamp when the session was created"
|
|
143
|
+
},
|
|
144
|
+
expiresAt: {
|
|
145
|
+
type: "string",
|
|
146
|
+
format: "date-time",
|
|
147
|
+
description: "Timestamp when the session expires"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
required: [
|
|
151
|
+
"token",
|
|
152
|
+
"userId",
|
|
153
|
+
"createdAt",
|
|
154
|
+
"expiresAt"
|
|
155
|
+
],
|
|
156
|
+
description: "The current session object, included unless disableSession is true"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
required: ["user", "session"]
|
|
160
|
+
} } }
|
|
161
|
+
} }
|
|
162
|
+
} }
|
|
163
|
+
}, async (ctx) => {
|
|
164
|
+
const { session, valid } = await verifyTwoFactor(ctx);
|
|
165
|
+
const user = session.user;
|
|
166
|
+
const twoFactor = await ctx.context.adapter.findOne({
|
|
167
|
+
model: twoFactorTable,
|
|
168
|
+
where: [{
|
|
169
|
+
field: "userId",
|
|
170
|
+
value: user.id
|
|
171
|
+
}]
|
|
172
|
+
});
|
|
173
|
+
if (!twoFactor) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.BACKUP_CODES_NOT_ENABLED);
|
|
174
|
+
const validate = await verifyBackupCode({
|
|
175
|
+
backupCodes: twoFactor.backupCodes,
|
|
176
|
+
code: ctx.body.code
|
|
177
|
+
}, ctx.context.secret, opts);
|
|
178
|
+
if (!validate.status) throw APIError.from("UNAUTHORIZED", TWO_FACTOR_ERROR_CODES.INVALID_BACKUP_CODE);
|
|
179
|
+
const updatedBackupCodes = await symmetricEncrypt({
|
|
180
|
+
key: ctx.context.secret,
|
|
181
|
+
data: JSON.stringify(validate.updated)
|
|
182
|
+
});
|
|
183
|
+
if (!await ctx.context.adapter.update({
|
|
184
|
+
model: twoFactorTable,
|
|
185
|
+
update: { backupCodes: updatedBackupCodes },
|
|
186
|
+
where: [{
|
|
187
|
+
field: "id",
|
|
188
|
+
value: twoFactor.id
|
|
189
|
+
}, {
|
|
190
|
+
field: "backupCodes",
|
|
191
|
+
value: twoFactor.backupCodes
|
|
192
|
+
}]
|
|
193
|
+
})) throw APIError.fromStatus("CONFLICT", { message: "Failed to verify backup code. Please try again." });
|
|
194
|
+
if (!ctx.body.disableSession) return valid(ctx);
|
|
195
|
+
return ctx.json({
|
|
196
|
+
token: session.session?.token,
|
|
197
|
+
user: parseUserOutput(ctx.context.options, session.user)
|
|
198
|
+
});
|
|
199
|
+
}),
|
|
200
|
+
generateBackupCodes: createAuthEndpoint("/two-factor/generate-backup-codes", {
|
|
201
|
+
method: "POST",
|
|
202
|
+
body: generateBackupCodesBodySchema,
|
|
203
|
+
use: [sessionMiddleware],
|
|
204
|
+
metadata: { openapi: {
|
|
205
|
+
description: "Generate new backup codes for two-factor authentication",
|
|
206
|
+
responses: { "200": {
|
|
207
|
+
description: "Backup codes generated successfully",
|
|
208
|
+
content: { "application/json": { schema: {
|
|
209
|
+
type: "object",
|
|
210
|
+
properties: {
|
|
211
|
+
status: {
|
|
212
|
+
type: "boolean",
|
|
213
|
+
description: "Indicates if the backup codes were generated successfully",
|
|
214
|
+
enum: [true]
|
|
215
|
+
},
|
|
216
|
+
backupCodes: {
|
|
217
|
+
type: "array",
|
|
218
|
+
items: { type: "string" },
|
|
219
|
+
description: "Array of generated backup codes in plain text"
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
required: ["status", "backupCodes"]
|
|
223
|
+
} } }
|
|
224
|
+
} }
|
|
225
|
+
} }
|
|
226
|
+
}, async (ctx) => {
|
|
227
|
+
const user = ctx.context.session.user;
|
|
228
|
+
if (!user.twoFactorEnabled) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.TWO_FACTOR_NOT_ENABLED);
|
|
229
|
+
await ctx.context.password.checkPassword(user.id, ctx);
|
|
230
|
+
const twoFactor = await ctx.context.adapter.findOne({
|
|
231
|
+
model: twoFactorTable,
|
|
232
|
+
where: [{
|
|
233
|
+
field: "userId",
|
|
234
|
+
value: user.id
|
|
235
|
+
}]
|
|
236
|
+
});
|
|
237
|
+
if (!twoFactor) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.TWO_FACTOR_NOT_ENABLED);
|
|
238
|
+
const backupCodes = await generateBackupCodes(ctx.context.secret, opts);
|
|
239
|
+
await ctx.context.adapter.update({
|
|
240
|
+
model: twoFactorTable,
|
|
241
|
+
update: { backupCodes: backupCodes.encryptedBackupCodes },
|
|
242
|
+
where: [{
|
|
243
|
+
field: "id",
|
|
244
|
+
value: twoFactor.id
|
|
245
|
+
}]
|
|
246
|
+
});
|
|
247
|
+
return ctx.json({
|
|
248
|
+
status: true,
|
|
249
|
+
backupCodes: backupCodes.backupCodes
|
|
250
|
+
});
|
|
251
|
+
}),
|
|
252
|
+
viewBackupCodes: createAuthEndpoint({
|
|
253
|
+
method: "POST",
|
|
254
|
+
body: viewBackupCodesBodySchema
|
|
255
|
+
}, async (ctx) => {
|
|
256
|
+
const twoFactor = await ctx.context.adapter.findOne({
|
|
257
|
+
model: twoFactorTable,
|
|
258
|
+
where: [{
|
|
259
|
+
field: "userId",
|
|
260
|
+
value: ctx.body.userId
|
|
261
|
+
}]
|
|
262
|
+
});
|
|
263
|
+
if (!twoFactor) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.BACKUP_CODES_NOT_ENABLED);
|
|
264
|
+
const decryptedBackupCodes = await getBackupCodes(twoFactor.backupCodes, ctx.context.secret, opts);
|
|
265
|
+
if (!decryptedBackupCodes) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.INVALID_BACKUP_CODE);
|
|
266
|
+
return ctx.json({
|
|
267
|
+
status: true,
|
|
268
|
+
backupCodes: decryptedBackupCodes
|
|
269
|
+
});
|
|
270
|
+
})
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
//#endregion
|
|
276
|
+
export { backupCode2fa, generateBackupCodes };
|
|
277
|
+
//# sourceMappingURL=index.mjs.map
|