@hammadj/better-auth 1.5.0-beta.9
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 +33 -0
- package/dist/_virtual/rolldown_runtime.mjs +36 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +1 -0
- package/dist/adapters/drizzle-adapter/index.mjs +3 -0
- package/dist/adapters/index.d.mts +23 -0
- package/dist/adapters/index.mjs +13 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/adapters/kysely-adapter/index.d.mts +1 -0
- package/dist/adapters/kysely-adapter/index.mjs +3 -0
- package/dist/adapters/memory-adapter/index.d.mts +1 -0
- package/dist/adapters/memory-adapter/index.mjs +3 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +1 -0
- package/dist/adapters/mongodb-adapter/index.mjs +3 -0
- package/dist/adapters/prisma-adapter/index.d.mts +1 -0
- package/dist/adapters/prisma-adapter/index.mjs +3 -0
- package/dist/api/index.d.mts +40 -0
- package/dist/api/index.mjs +205 -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 +17 -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 +177 -0
- package/dist/api/rate-limiter/index.mjs.map +1 -0
- package/dist/api/routes/account.d.mts +10 -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 +5 -0
- package/dist/api/routes/callback.mjs +178 -0
- package/dist/api/routes/callback.mjs.map +1 -0
- package/dist/api/routes/email-verification.d.mts +29 -0
- package/dist/api/routes/email-verification.mjs +301 -0
- package/dist/api/routes/email-verification.mjs.map +1 -0
- package/dist/api/routes/error.d.mts +5 -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 +5 -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 +8 -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 +52 -0
- package/dist/api/routes/session.mjs +478 -0
- package/dist/api/routes/session.mjs.map +1 -0
- package/dist/api/routes/sign-in.d.mts +8 -0
- package/dist/api/routes/sign-in.mjs +262 -0
- package/dist/api/routes/sign-in.mjs.map +1 -0
- package/dist/api/routes/sign-out.d.mts +5 -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 +7 -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 +12 -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 +5 -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 +44 -0
- package/dist/auth/base.mjs.map +1 -0
- package/dist/auth/full.d.mts +30 -0
- package/dist/auth/full.mjs +32 -0
- package/dist/auth/full.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 +30 -0
- package/dist/client/index.mjs +21 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/client/lynx/index.d.mts +62 -0
- package/dist/client/lynx/index.mjs +24 -0
- package/dist/client/lynx/index.mjs.map +1 -0
- package/dist/client/lynx/lynx-store.d.mts +47 -0
- package/dist/client/lynx/lynx-store.mjs +47 -0
- package/dist/client/lynx/lynx-store.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 +57 -0
- package/dist/client/plugins/index.d.mts +58 -0
- package/dist/client/plugins/index.mjs +33 -0
- package/dist/client/plugins/infer-plugin.d.mts +9 -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 +63 -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/solid/index.d.mts +57 -0
- package/dist/client/solid/index.mjs +22 -0
- package/dist/client/solid/index.mjs.map +1 -0
- package/dist/client/solid/solid-store.mjs +24 -0
- package/dist/client/solid/solid-store.mjs.map +1 -0
- package/dist/client/svelte/index.d.mts +63 -0
- package/dist/client/svelte/index.mjs +20 -0
- package/dist/client/svelte/index.mjs.map +1 -0
- package/dist/client/types.d.mts +58 -0
- package/dist/client/vanilla.d.mts +62 -0
- package/dist/client/vanilla.mjs +20 -0
- package/dist/client/vanilla.mjs.map +1 -0
- package/dist/client/vue/index.d.mts +86 -0
- package/dist/client/vue/index.mjs +38 -0
- package/dist/client/vue/index.mjs.map +1 -0
- package/dist/client/vue/vue-store.mjs +26 -0
- package/dist/client/vue/vue-store.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 +62 -0
- package/dist/context/helpers.mjs.map +1 -0
- package/dist/context/init-minimal.mjs +20 -0
- package/dist/context/init-minimal.mjs.map +1 -0
- package/dist/context/init.mjs +22 -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 +67 -0
- package/dist/cookies/index.mjs +264 -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 +28 -0
- package/dist/db/adapter-base.mjs.map +1 -0
- package/dist/db/adapter-kysely.d.mts +8 -0
- package/dist/db/adapter-kysely.mjs +21 -0
- package/dist/db/adapter-kysely.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 +55 -0
- package/dist/db/field.mjs +11 -0
- package/dist/db/field.mjs.map +1 -0
- package/dist/db/get-migration.d.mts +23 -0
- package/dist/db/get-migration.mjs +339 -0
- package/dist/db/get-migration.mjs.map +1 -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 +9 -0
- package/dist/db/index.mjs +36 -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 +26 -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 +52 -0
- package/dist/index.mjs +26 -0
- package/dist/integrations/next-js.d.mts +14 -0
- package/dist/integrations/next-js.mjs +78 -0
- package/dist/integrations/next-js.mjs.map +1 -0
- package/dist/integrations/node.d.mts +13 -0
- package/dist/integrations/node.mjs +16 -0
- package/dist/integrations/node.mjs.map +1 -0
- package/dist/integrations/solid-start.d.mts +23 -0
- package/dist/integrations/solid-start.mjs +17 -0
- package/dist/integrations/solid-start.mjs.map +1 -0
- package/dist/integrations/svelte-kit.d.mts +29 -0
- package/dist/integrations/svelte-kit.mjs +57 -0
- package/dist/integrations/svelte-kit.mjs.map +1 -0
- package/dist/integrations/tanstack-start-solid.d.mts +22 -0
- package/dist/integrations/tanstack-start-solid.mjs +61 -0
- package/dist/integrations/tanstack-start-solid.mjs.map +1 -0
- package/dist/integrations/tanstack-start.d.mts +22 -0
- package/dist/integrations/tanstack-start.mjs +61 -0
- package/dist/integrations/tanstack-start.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 +31 -0
- package/dist/oauth2/link-account.mjs +144 -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 +14 -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 +14 -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 +14 -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 +5 -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 +855 -0
- package/dist/plugins/admin/routes.mjs.map +1 -0
- package/dist/plugins/admin/schema.d.mts +6 -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/anonymous/client.d.mts +9 -0
- package/dist/plugins/anonymous/client.mjs +22 -0
- package/dist/plugins/anonymous/client.mjs.map +1 -0
- package/dist/plugins/anonymous/error-codes.d.mts +5 -0
- package/dist/plugins/anonymous/error-codes.mjs +16 -0
- package/dist/plugins/anonymous/error-codes.mjs.map +1 -0
- package/dist/plugins/anonymous/index.d.mts +14 -0
- package/dist/plugins/anonymous/index.mjs +163 -0
- package/dist/plugins/anonymous/index.mjs.map +1 -0
- package/dist/plugins/anonymous/schema.d.mts +5 -0
- package/dist/plugins/anonymous/schema.mjs +11 -0
- package/dist/plugins/anonymous/schema.mjs.map +1 -0
- package/dist/plugins/anonymous/types.d.mts +68 -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 +9 -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 +5 -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 +17 -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 +223 -0
- package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/schema.d.mts +11 -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 +25 -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 +14 -0
- package/dist/plugins/captcha/index.mjs +60 -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 +27 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +25 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +29 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +27 -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 +10 -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 +26 -0
- package/dist/plugins/custom-session/index.mjs +70 -0
- package/dist/plugins/custom-session/index.mjs.map +1 -0
- package/dist/plugins/device-authorization/client.d.mts +5 -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 +28 -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 +7 -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 +5 -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 +14 -0
- package/dist/plugins/email-otp/index.mjs +108 -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 +564 -0
- package/dist/plugins/email-otp/routes.mjs.map +1 -0
- package/dist/plugins/email-otp/types.d.mts +74 -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 +19 -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 +5 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +15 -0
- package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/index.d.mts +34 -0
- package/dist/plugins/generic-oauth/index.mjs +137 -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 +394 -0
- package/dist/plugins/generic-oauth/routes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/types.d.mts +145 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +21 -0
- package/dist/plugins/haveibeenpwned/index.mjs +56 -0
- package/dist/plugins/haveibeenpwned/index.mjs.map +1 -0
- package/dist/plugins/index.d.mts +68 -0
- package/dist/plugins/index.mjs +51 -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 +18 -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 +17 -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 +5 -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 +18 -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 +52 -0
- package/dist/plugins/last-login-method/index.mjs +77 -0
- package/dist/plugins/last-login-method/index.mjs.map +1 -0
- package/dist/plugins/magic-link/client.d.mts +5 -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 +61 -0
- package/dist/plugins/magic-link/index.mjs +167 -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 +46 -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 +8 -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 +5 -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 +22 -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 +39 -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 +44 -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 +8 -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 +32 -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 +26 -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 +159 -0
- package/dist/plugins/one-tap/client.mjs +214 -0
- package/dist/plugins/one-tap/client.mjs.map +1 -0
- package/dist/plugins/one-tap/index.d.mts +27 -0
- package/dist/plugins/one-tap/index.mjs +96 -0
- package/dist/plugins/one-tap/index.mjs.map +1 -0
- package/dist/plugins/one-time-token/client.d.mts +7 -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 +53 -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 +45 -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 +205 -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 +151 -0
- package/dist/plugins/organization/client.mjs +107 -0
- package/dist/plugins/organization/client.mjs.map +1 -0
- package/dist/plugins/organization/error-codes.d.mts +5 -0
- package/dist/plugins/organization/error-codes.mjs +65 -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 +252 -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 +26 -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 +11 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +656 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +16 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +555 -0
- package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +13 -0
- package/dist/plugins/organization/routes/crud-members.mjs +473 -0
- package/dist/plugins/organization/routes/crud-members.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +13 -0
- package/dist/plugins/organization/routes/crud-org.mjs +447 -0
- package/dist/plugins/organization/routes/crud-org.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +15 -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 +733 -0
- package/dist/plugins/phone-number/client.d.mts +8 -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 +5 -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 +14 -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 +459 -0
- package/dist/plugins/phone-number/routes.mjs.map +1 -0
- package/dist/plugins/phone-number/schema.d.mts +5 -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/siwe/client.d.mts +5 -0
- package/dist/plugins/siwe/client.mjs +11 -0
- package/dist/plugins/siwe/client.mjs.map +1 -0
- package/dist/plugins/siwe/error-codes.mjs +13 -0
- package/dist/plugins/siwe/error-codes.mjs.map +1 -0
- package/dist/plugins/siwe/index.d.mts +26 -0
- package/dist/plugins/siwe/index.mjs +261 -0
- package/dist/plugins/siwe/index.mjs.map +1 -0
- package/dist/plugins/siwe/schema.d.mts +5 -0
- package/dist/plugins/siwe/schema.mjs +32 -0
- package/dist/plugins/siwe/schema.mjs.map +1 -0
- package/dist/plugins/siwe/types.d.mts +44 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +91 -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 +17 -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 +5 -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 +19 -0
- package/dist/plugins/two-factor/index.mjs +207 -0
- package/dist/plugins/two-factor/index.mjs.map +1 -0
- package/dist/plugins/two-factor/otp/index.d.mts +96 -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 +5 -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 +81 -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 +65 -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 +76 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs.map +1 -0
- package/dist/plugins/username/client.d.mts +7 -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 +5 -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 +74 -0
- package/dist/plugins/username/index.mjs +237 -0
- package/dist/plugins/username/index.mjs.map +1 -0
- package/dist/plugins/username/schema.d.mts +9 -0
- package/dist/plugins/username/schema.mjs +26 -0
- package/dist/plugins/username/schema.mjs.map +1 -0
- package/dist/social-providers/index.d.mts +1 -0
- package/dist/social-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/test-utils/headers.d.mts +9 -0
- package/dist/test-utils/headers.mjs +24 -0
- package/dist/test-utils/headers.mjs.map +1 -0
- package/dist/test-utils/index.d.mts +3 -0
- package/dist/test-utils/index.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +181 -0
- package/dist/test-utils/test-instance.mjs +210 -0
- package/dist/test-utils/test-instance.mjs.map +1 -0
- package/dist/types/adapter.d.mts +24 -0
- package/dist/types/api.d.mts +29 -0
- package/dist/types/auth.d.mts +30 -0
- package/dist/types/helper.d.mts +21 -0
- package/dist/types/index.d.mts +11 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +17 -0
- package/dist/types/plugins.d.mts +16 -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/hashing.mjs +21 -0
- package/dist/utils/hashing.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 +3 -0
- package/dist/utils/index.mjs +5 -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 +6 -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.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 +601 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import { getIp } from "../utils/get-request-ip.mjs";
|
|
2
|
+
import { parseSessionInput, parseSessionOutput, parseUserOutput } from "./schema.mjs";
|
|
3
|
+
import { getDate } from "../utils/date.mjs";
|
|
4
|
+
import { getStorageOption, processIdentifier } from "./verification-token-storage.mjs";
|
|
5
|
+
import { getWithHooks } from "./with-hooks.mjs";
|
|
6
|
+
import { getCurrentAdapter, getCurrentAuthContext, runWithTransaction } from "@better-auth/core/context";
|
|
7
|
+
import { generateId } from "@better-auth/core/utils/id";
|
|
8
|
+
import { safeJSONParse } from "@better-auth/core/utils/json";
|
|
9
|
+
|
|
10
|
+
//#region src/db/internal-adapter.ts
|
|
11
|
+
function getTTLSeconds(expiresAt, now = Date.now()) {
|
|
12
|
+
const expiresMs = typeof expiresAt === "number" ? expiresAt : expiresAt.getTime();
|
|
13
|
+
return Math.max(Math.floor((expiresMs - now) / 1e3), 0);
|
|
14
|
+
}
|
|
15
|
+
const createInternalAdapter = (adapter, ctx) => {
|
|
16
|
+
const logger = ctx.logger;
|
|
17
|
+
const options = ctx.options;
|
|
18
|
+
const secondaryStorage = options.secondaryStorage;
|
|
19
|
+
const sessionExpiration = options.session?.expiresIn || 3600 * 24 * 7;
|
|
20
|
+
const { createWithHooks, updateWithHooks, updateManyWithHooks, deleteWithHooks, deleteManyWithHooks } = getWithHooks(adapter, ctx);
|
|
21
|
+
async function refreshUserSessions(user) {
|
|
22
|
+
if (!secondaryStorage) return;
|
|
23
|
+
const listRaw = await secondaryStorage.get(`active-sessions-${user.id}`);
|
|
24
|
+
if (!listRaw) return;
|
|
25
|
+
const now = Date.now();
|
|
26
|
+
const validSessions = (safeJSONParse(listRaw) || []).filter((s) => s.expiresAt > now);
|
|
27
|
+
await Promise.all(validSessions.map(async ({ token }) => {
|
|
28
|
+
const cached = await secondaryStorage.get(token);
|
|
29
|
+
if (!cached) return;
|
|
30
|
+
const parsed = safeJSONParse(cached);
|
|
31
|
+
if (!parsed) return;
|
|
32
|
+
const sessionTTL = getTTLSeconds(parsed.session.expiresAt, now);
|
|
33
|
+
await secondaryStorage.set(token, JSON.stringify({
|
|
34
|
+
session: parsed.session,
|
|
35
|
+
user
|
|
36
|
+
}), Math.floor(sessionTTL));
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
createOAuthUser: async (user, account) => {
|
|
41
|
+
return runWithTransaction(adapter, async () => {
|
|
42
|
+
const createdUser = await createWithHooks({
|
|
43
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
44
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
45
|
+
...user
|
|
46
|
+
}, "user", void 0);
|
|
47
|
+
return {
|
|
48
|
+
user: createdUser,
|
|
49
|
+
account: await createWithHooks({
|
|
50
|
+
...account,
|
|
51
|
+
userId: createdUser.id,
|
|
52
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
53
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
54
|
+
}, "account", void 0)
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
createUser: async (user) => {
|
|
59
|
+
return await createWithHooks({
|
|
60
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
61
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
62
|
+
...user,
|
|
63
|
+
email: user.email?.toLowerCase()
|
|
64
|
+
}, "user", void 0);
|
|
65
|
+
},
|
|
66
|
+
createAccount: async (account) => {
|
|
67
|
+
return await createWithHooks({
|
|
68
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
69
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
70
|
+
...account
|
|
71
|
+
}, "account", void 0);
|
|
72
|
+
},
|
|
73
|
+
listSessions: async (userId) => {
|
|
74
|
+
if (secondaryStorage) {
|
|
75
|
+
const currentList = await secondaryStorage.get(`active-sessions-${userId}`);
|
|
76
|
+
if (!currentList) return [];
|
|
77
|
+
const list = safeJSONParse(currentList) || [];
|
|
78
|
+
const now = Date.now();
|
|
79
|
+
const seenTokens = /* @__PURE__ */ new Set();
|
|
80
|
+
const sessions = [];
|
|
81
|
+
for (const { token, expiresAt } of list) {
|
|
82
|
+
if (expiresAt <= now || seenTokens.has(token)) continue;
|
|
83
|
+
seenTokens.add(token);
|
|
84
|
+
const data = await secondaryStorage.get(token);
|
|
85
|
+
if (!data) continue;
|
|
86
|
+
try {
|
|
87
|
+
const parsed = typeof data === "string" ? JSON.parse(data) : data;
|
|
88
|
+
if (!parsed?.session) continue;
|
|
89
|
+
sessions.push(parseSessionOutput(ctx.options, {
|
|
90
|
+
...parsed.session,
|
|
91
|
+
expiresAt: new Date(parsed.session.expiresAt)
|
|
92
|
+
}));
|
|
93
|
+
} catch {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return sessions;
|
|
98
|
+
}
|
|
99
|
+
return await (await getCurrentAdapter(adapter)).findMany({
|
|
100
|
+
model: "session",
|
|
101
|
+
where: [{
|
|
102
|
+
field: "userId",
|
|
103
|
+
value: userId
|
|
104
|
+
}]
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
listUsers: async (limit, offset, sortBy, where) => {
|
|
108
|
+
return await (await getCurrentAdapter(adapter)).findMany({
|
|
109
|
+
model: "user",
|
|
110
|
+
limit,
|
|
111
|
+
offset,
|
|
112
|
+
sortBy,
|
|
113
|
+
where
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
countTotalUsers: async (where) => {
|
|
117
|
+
const total = await (await getCurrentAdapter(adapter)).count({
|
|
118
|
+
model: "user",
|
|
119
|
+
where
|
|
120
|
+
});
|
|
121
|
+
if (typeof total === "string") return parseInt(total);
|
|
122
|
+
return total;
|
|
123
|
+
},
|
|
124
|
+
deleteUser: async (userId) => {
|
|
125
|
+
if (!secondaryStorage || options.session?.storeSessionInDatabase) await deleteManyWithHooks([{
|
|
126
|
+
field: "userId",
|
|
127
|
+
value: userId
|
|
128
|
+
}], "session", void 0);
|
|
129
|
+
await deleteManyWithHooks([{
|
|
130
|
+
field: "userId",
|
|
131
|
+
value: userId
|
|
132
|
+
}], "account", void 0);
|
|
133
|
+
await deleteWithHooks([{
|
|
134
|
+
field: "id",
|
|
135
|
+
value: userId
|
|
136
|
+
}], "user", void 0);
|
|
137
|
+
},
|
|
138
|
+
createSession: async (userId, dontRememberMe, override, overrideAll) => {
|
|
139
|
+
const headers = await (async () => {
|
|
140
|
+
const ctx = await getCurrentAuthContext().catch(() => null);
|
|
141
|
+
return ctx?.headers || ctx?.request?.headers;
|
|
142
|
+
})();
|
|
143
|
+
const storeInDb = options.session?.storeSessionInDatabase;
|
|
144
|
+
const { id: _, ...rest } = override || {};
|
|
145
|
+
const defaultAdditionalFields = parseSessionInput(options, {});
|
|
146
|
+
const data = {
|
|
147
|
+
ipAddress: headers ? getIp(headers, options) || "" : "",
|
|
148
|
+
userAgent: headers?.get("user-agent") || "",
|
|
149
|
+
...rest,
|
|
150
|
+
expiresAt: dontRememberMe ? getDate(3600 * 24, "sec") : getDate(sessionExpiration, "sec"),
|
|
151
|
+
userId,
|
|
152
|
+
token: generateId(32),
|
|
153
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
154
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
155
|
+
...defaultAdditionalFields,
|
|
156
|
+
...overrideAll ? rest : {}
|
|
157
|
+
};
|
|
158
|
+
return await createWithHooks(data, "session", secondaryStorage ? {
|
|
159
|
+
fn: async (sessionData) => {
|
|
160
|
+
/**
|
|
161
|
+
* store the session token for the user
|
|
162
|
+
* so we can retrieve it later for listing sessions
|
|
163
|
+
*/
|
|
164
|
+
const currentList = await secondaryStorage.get(`active-sessions-${userId}`);
|
|
165
|
+
let list = [];
|
|
166
|
+
const now = Date.now();
|
|
167
|
+
if (currentList) {
|
|
168
|
+
list = safeJSONParse(currentList) || [];
|
|
169
|
+
list = list.filter((session) => session.expiresAt > now && session.token !== data.token);
|
|
170
|
+
}
|
|
171
|
+
const sorted = [...list, {
|
|
172
|
+
token: data.token,
|
|
173
|
+
expiresAt: data.expiresAt.getTime()
|
|
174
|
+
}].sort((a, b) => a.expiresAt - b.expiresAt);
|
|
175
|
+
const furthestSessionTTL = getTTLSeconds(sorted.at(-1)?.expiresAt ?? data.expiresAt.getTime(), now);
|
|
176
|
+
if (furthestSessionTTL > 0) await secondaryStorage.set(`active-sessions-${userId}`, JSON.stringify(sorted), furthestSessionTTL);
|
|
177
|
+
const user = await adapter.findOne({
|
|
178
|
+
model: "user",
|
|
179
|
+
where: [{
|
|
180
|
+
field: "id",
|
|
181
|
+
value: userId
|
|
182
|
+
}]
|
|
183
|
+
});
|
|
184
|
+
const sessionTTL = getTTLSeconds(data.expiresAt, now);
|
|
185
|
+
if (sessionTTL > 0) await secondaryStorage.set(data.token, JSON.stringify({
|
|
186
|
+
session: sessionData,
|
|
187
|
+
user
|
|
188
|
+
}), sessionTTL);
|
|
189
|
+
return sessionData;
|
|
190
|
+
},
|
|
191
|
+
executeMainFn: storeInDb
|
|
192
|
+
} : void 0);
|
|
193
|
+
},
|
|
194
|
+
findSession: async (token) => {
|
|
195
|
+
if (secondaryStorage) {
|
|
196
|
+
const sessionStringified = await secondaryStorage.get(token);
|
|
197
|
+
if (!sessionStringified && !options.session?.storeSessionInDatabase) return null;
|
|
198
|
+
if (sessionStringified) {
|
|
199
|
+
const s = safeJSONParse(sessionStringified);
|
|
200
|
+
if (!s) return null;
|
|
201
|
+
return {
|
|
202
|
+
session: parseSessionOutput(ctx.options, {
|
|
203
|
+
...s.session,
|
|
204
|
+
expiresAt: new Date(s.session.expiresAt),
|
|
205
|
+
createdAt: new Date(s.session.createdAt),
|
|
206
|
+
updatedAt: new Date(s.session.updatedAt)
|
|
207
|
+
}),
|
|
208
|
+
user: parseUserOutput(ctx.options, {
|
|
209
|
+
...s.user,
|
|
210
|
+
createdAt: new Date(s.user.createdAt),
|
|
211
|
+
updatedAt: new Date(s.user.updatedAt)
|
|
212
|
+
})
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const result = await (await getCurrentAdapter(adapter)).findOne({
|
|
217
|
+
model: "session",
|
|
218
|
+
where: [{
|
|
219
|
+
value: token,
|
|
220
|
+
field: "token"
|
|
221
|
+
}],
|
|
222
|
+
join: { user: true }
|
|
223
|
+
});
|
|
224
|
+
if (!result) return null;
|
|
225
|
+
const { user, ...session } = result;
|
|
226
|
+
if (!user) return null;
|
|
227
|
+
return {
|
|
228
|
+
session: parseSessionOutput(ctx.options, session),
|
|
229
|
+
user: parseUserOutput(ctx.options, user)
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
findSessions: async (sessionTokens) => {
|
|
233
|
+
if (secondaryStorage) {
|
|
234
|
+
const sessions = [];
|
|
235
|
+
for (const sessionToken of sessionTokens) {
|
|
236
|
+
const sessionStringified = await secondaryStorage.get(sessionToken);
|
|
237
|
+
if (sessionStringified) try {
|
|
238
|
+
const s = typeof sessionStringified === "string" ? JSON.parse(sessionStringified) : sessionStringified;
|
|
239
|
+
if (!s?.session) continue;
|
|
240
|
+
const session = {
|
|
241
|
+
session: {
|
|
242
|
+
...s.session,
|
|
243
|
+
expiresAt: new Date(s.session.expiresAt)
|
|
244
|
+
},
|
|
245
|
+
user: {
|
|
246
|
+
...s.user,
|
|
247
|
+
createdAt: new Date(s.user.createdAt),
|
|
248
|
+
updatedAt: new Date(s.user.updatedAt)
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
sessions.push(session);
|
|
252
|
+
} catch {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return sessions;
|
|
257
|
+
}
|
|
258
|
+
const sessions = await (await getCurrentAdapter(adapter)).findMany({
|
|
259
|
+
model: "session",
|
|
260
|
+
where: [{
|
|
261
|
+
field: "token",
|
|
262
|
+
value: sessionTokens,
|
|
263
|
+
operator: "in"
|
|
264
|
+
}],
|
|
265
|
+
join: { user: true }
|
|
266
|
+
});
|
|
267
|
+
if (!sessions.length) return [];
|
|
268
|
+
if (sessions.some((session) => !session.user)) return [];
|
|
269
|
+
return sessions.map((_session) => {
|
|
270
|
+
const { user, ...session } = _session;
|
|
271
|
+
return {
|
|
272
|
+
session,
|
|
273
|
+
user
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
},
|
|
277
|
+
updateSession: async (sessionToken, session) => {
|
|
278
|
+
return await updateWithHooks(session, [{
|
|
279
|
+
field: "token",
|
|
280
|
+
value: sessionToken
|
|
281
|
+
}], "session", secondaryStorage ? {
|
|
282
|
+
async fn(data) {
|
|
283
|
+
const currentSession = await secondaryStorage.get(sessionToken);
|
|
284
|
+
if (!currentSession) return null;
|
|
285
|
+
const parsedSession = safeJSONParse(currentSession);
|
|
286
|
+
if (!parsedSession) return null;
|
|
287
|
+
const mergedSession = {
|
|
288
|
+
...parsedSession.session,
|
|
289
|
+
...data,
|
|
290
|
+
expiresAt: new Date(data.expiresAt ?? parsedSession.session.expiresAt),
|
|
291
|
+
createdAt: new Date(parsedSession.session.createdAt),
|
|
292
|
+
updatedAt: new Date(data.updatedAt ?? parsedSession.session.updatedAt)
|
|
293
|
+
};
|
|
294
|
+
const updatedSession = parseSessionOutput(ctx.options, mergedSession);
|
|
295
|
+
const now = Date.now();
|
|
296
|
+
const expiresMs = new Date(updatedSession.expiresAt).getTime();
|
|
297
|
+
const sessionTTL = getTTLSeconds(expiresMs, now);
|
|
298
|
+
if (sessionTTL > 0) {
|
|
299
|
+
await secondaryStorage.set(sessionToken, JSON.stringify({
|
|
300
|
+
session: updatedSession,
|
|
301
|
+
user: parsedSession.user
|
|
302
|
+
}), sessionTTL);
|
|
303
|
+
const listKey = `active-sessions-${updatedSession.userId}`;
|
|
304
|
+
const listRaw = await secondaryStorage.get(listKey);
|
|
305
|
+
const sorted = (listRaw ? safeJSONParse(listRaw) || [] : []).filter((s) => s.token !== sessionToken && s.expiresAt > now).concat([{
|
|
306
|
+
token: sessionToken,
|
|
307
|
+
expiresAt: expiresMs
|
|
308
|
+
}]).sort((a, b) => a.expiresAt - b.expiresAt);
|
|
309
|
+
const furthestSessionExp = sorted.at(-1)?.expiresAt;
|
|
310
|
+
if (furthestSessionExp && furthestSessionExp > now) await secondaryStorage.set(listKey, JSON.stringify(sorted), getTTLSeconds(furthestSessionExp, now));
|
|
311
|
+
else await secondaryStorage.delete(listKey);
|
|
312
|
+
}
|
|
313
|
+
return updatedSession;
|
|
314
|
+
},
|
|
315
|
+
executeMainFn: options.session?.storeSessionInDatabase
|
|
316
|
+
} : void 0);
|
|
317
|
+
},
|
|
318
|
+
deleteSession: async (token) => {
|
|
319
|
+
if (secondaryStorage) {
|
|
320
|
+
const data = await secondaryStorage.get(token);
|
|
321
|
+
if (data) {
|
|
322
|
+
const { session } = safeJSONParse(data) ?? {};
|
|
323
|
+
if (!session) {
|
|
324
|
+
logger.error("Session not found in secondary storage");
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const userId = session.userId;
|
|
328
|
+
const currentList = await secondaryStorage.get(`active-sessions-${userId}`);
|
|
329
|
+
if (currentList) {
|
|
330
|
+
const list = safeJSONParse(currentList) || [];
|
|
331
|
+
const now = Date.now();
|
|
332
|
+
const filtered = list.filter((session) => session.expiresAt > now && session.token !== token);
|
|
333
|
+
const furthestSessionExp = filtered.sort((a, b) => a.expiresAt - b.expiresAt).at(-1)?.expiresAt;
|
|
334
|
+
if (filtered.length > 0 && furthestSessionExp && furthestSessionExp > Date.now()) await secondaryStorage.set(`active-sessions-${userId}`, JSON.stringify(filtered), getTTLSeconds(furthestSessionExp, now));
|
|
335
|
+
else await secondaryStorage.delete(`active-sessions-${userId}`);
|
|
336
|
+
} else logger.error("Active sessions list not found in secondary storage");
|
|
337
|
+
}
|
|
338
|
+
await secondaryStorage.delete(token);
|
|
339
|
+
if (!options.session?.storeSessionInDatabase || ctx.options.session?.preserveSessionInDatabase) return;
|
|
340
|
+
}
|
|
341
|
+
await deleteWithHooks([{
|
|
342
|
+
field: "token",
|
|
343
|
+
value: token
|
|
344
|
+
}], "session", void 0);
|
|
345
|
+
},
|
|
346
|
+
deleteAccounts: async (userId) => {
|
|
347
|
+
await deleteManyWithHooks([{
|
|
348
|
+
field: "userId",
|
|
349
|
+
value: userId
|
|
350
|
+
}], "account", void 0);
|
|
351
|
+
},
|
|
352
|
+
deleteAccount: async (accountId) => {
|
|
353
|
+
await deleteWithHooks([{
|
|
354
|
+
field: "id",
|
|
355
|
+
value: accountId
|
|
356
|
+
}], "account", void 0);
|
|
357
|
+
},
|
|
358
|
+
deleteSessions: async (userIdOrSessionTokens) => {
|
|
359
|
+
if (secondaryStorage) {
|
|
360
|
+
if (typeof userIdOrSessionTokens === "string") {
|
|
361
|
+
const activeSession = await secondaryStorage.get(`active-sessions-${userIdOrSessionTokens}`);
|
|
362
|
+
const sessions = activeSession ? safeJSONParse(activeSession) : [];
|
|
363
|
+
if (!sessions) return;
|
|
364
|
+
for (const session of sessions) await secondaryStorage.delete(session.token);
|
|
365
|
+
await secondaryStorage.delete(`active-sessions-${userIdOrSessionTokens}`);
|
|
366
|
+
} else for (const sessionToken of userIdOrSessionTokens) if (await secondaryStorage.get(sessionToken)) await secondaryStorage.delete(sessionToken);
|
|
367
|
+
if (!options.session?.storeSessionInDatabase || ctx.options.session?.preserveSessionInDatabase) return;
|
|
368
|
+
}
|
|
369
|
+
await deleteManyWithHooks([{
|
|
370
|
+
field: Array.isArray(userIdOrSessionTokens) ? "token" : "userId",
|
|
371
|
+
value: userIdOrSessionTokens,
|
|
372
|
+
operator: Array.isArray(userIdOrSessionTokens) ? "in" : void 0
|
|
373
|
+
}], "session", void 0);
|
|
374
|
+
},
|
|
375
|
+
findOAuthUser: async (email, accountId, providerId) => {
|
|
376
|
+
const account = await (await getCurrentAdapter(adapter)).findOne({
|
|
377
|
+
model: "account",
|
|
378
|
+
where: [{
|
|
379
|
+
value: accountId,
|
|
380
|
+
field: "accountId"
|
|
381
|
+
}, {
|
|
382
|
+
value: providerId,
|
|
383
|
+
field: "providerId"
|
|
384
|
+
}],
|
|
385
|
+
join: { user: true }
|
|
386
|
+
});
|
|
387
|
+
if (account) if (account.user) return {
|
|
388
|
+
user: account.user,
|
|
389
|
+
linkedAccount: account,
|
|
390
|
+
accounts: [account]
|
|
391
|
+
};
|
|
392
|
+
else {
|
|
393
|
+
const user = await (await getCurrentAdapter(adapter)).findOne({
|
|
394
|
+
model: "user",
|
|
395
|
+
where: [{
|
|
396
|
+
value: email.toLowerCase(),
|
|
397
|
+
field: "email"
|
|
398
|
+
}]
|
|
399
|
+
});
|
|
400
|
+
if (user) return {
|
|
401
|
+
user,
|
|
402
|
+
linkedAccount: account,
|
|
403
|
+
accounts: [account]
|
|
404
|
+
};
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
const user = await (await getCurrentAdapter(adapter)).findOne({
|
|
409
|
+
model: "user",
|
|
410
|
+
where: [{
|
|
411
|
+
value: email.toLowerCase(),
|
|
412
|
+
field: "email"
|
|
413
|
+
}]
|
|
414
|
+
});
|
|
415
|
+
if (user) return {
|
|
416
|
+
user,
|
|
417
|
+
linkedAccount: null,
|
|
418
|
+
accounts: await (await getCurrentAdapter(adapter)).findMany({
|
|
419
|
+
model: "account",
|
|
420
|
+
where: [{
|
|
421
|
+
value: user.id,
|
|
422
|
+
field: "userId"
|
|
423
|
+
}]
|
|
424
|
+
}) || []
|
|
425
|
+
};
|
|
426
|
+
else return null;
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
findUserByEmail: async (email, options) => {
|
|
430
|
+
const result = await (await getCurrentAdapter(adapter)).findOne({
|
|
431
|
+
model: "user",
|
|
432
|
+
where: [{
|
|
433
|
+
value: email.toLowerCase(),
|
|
434
|
+
field: "email"
|
|
435
|
+
}],
|
|
436
|
+
join: { ...options?.includeAccounts ? { account: true } : {} }
|
|
437
|
+
});
|
|
438
|
+
if (!result) return null;
|
|
439
|
+
const { account: accounts, ...user } = result;
|
|
440
|
+
return {
|
|
441
|
+
user,
|
|
442
|
+
accounts: accounts ?? []
|
|
443
|
+
};
|
|
444
|
+
},
|
|
445
|
+
findUserById: async (userId) => {
|
|
446
|
+
if (!userId) return null;
|
|
447
|
+
return await (await getCurrentAdapter(adapter)).findOne({
|
|
448
|
+
model: "user",
|
|
449
|
+
where: [{
|
|
450
|
+
field: "id",
|
|
451
|
+
value: userId
|
|
452
|
+
}]
|
|
453
|
+
});
|
|
454
|
+
},
|
|
455
|
+
linkAccount: async (account) => {
|
|
456
|
+
return await createWithHooks({
|
|
457
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
458
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
459
|
+
...account
|
|
460
|
+
}, "account", void 0);
|
|
461
|
+
},
|
|
462
|
+
updateUser: async (userId, data) => {
|
|
463
|
+
const user = await updateWithHooks(data, [{
|
|
464
|
+
field: "id",
|
|
465
|
+
value: userId
|
|
466
|
+
}], "user", void 0);
|
|
467
|
+
await refreshUserSessions(user);
|
|
468
|
+
return user;
|
|
469
|
+
},
|
|
470
|
+
updateUserByEmail: async (email, data) => {
|
|
471
|
+
const user = await updateWithHooks(data, [{
|
|
472
|
+
field: "email",
|
|
473
|
+
value: email.toLowerCase()
|
|
474
|
+
}], "user", void 0);
|
|
475
|
+
await refreshUserSessions(user);
|
|
476
|
+
return user;
|
|
477
|
+
},
|
|
478
|
+
updatePassword: async (userId, password) => {
|
|
479
|
+
await updateManyWithHooks({ password }, [{
|
|
480
|
+
field: "userId",
|
|
481
|
+
value: userId
|
|
482
|
+
}, {
|
|
483
|
+
field: "providerId",
|
|
484
|
+
value: "credential"
|
|
485
|
+
}], "account", void 0);
|
|
486
|
+
},
|
|
487
|
+
findAccounts: async (userId) => {
|
|
488
|
+
return await (await getCurrentAdapter(adapter)).findMany({
|
|
489
|
+
model: "account",
|
|
490
|
+
where: [{
|
|
491
|
+
field: "userId",
|
|
492
|
+
value: userId
|
|
493
|
+
}]
|
|
494
|
+
});
|
|
495
|
+
},
|
|
496
|
+
findAccount: async (accountId) => {
|
|
497
|
+
return await (await getCurrentAdapter(adapter)).findOne({
|
|
498
|
+
model: "account",
|
|
499
|
+
where: [{
|
|
500
|
+
field: "accountId",
|
|
501
|
+
value: accountId
|
|
502
|
+
}]
|
|
503
|
+
});
|
|
504
|
+
},
|
|
505
|
+
findAccountByProviderId: async (accountId, providerId) => {
|
|
506
|
+
return await (await getCurrentAdapter(adapter)).findOne({
|
|
507
|
+
model: "account",
|
|
508
|
+
where: [{
|
|
509
|
+
field: "accountId",
|
|
510
|
+
value: accountId
|
|
511
|
+
}, {
|
|
512
|
+
field: "providerId",
|
|
513
|
+
value: providerId
|
|
514
|
+
}]
|
|
515
|
+
});
|
|
516
|
+
},
|
|
517
|
+
findAccountByUserId: async (userId) => {
|
|
518
|
+
return await (await getCurrentAdapter(adapter)).findMany({
|
|
519
|
+
model: "account",
|
|
520
|
+
where: [{
|
|
521
|
+
field: "userId",
|
|
522
|
+
value: userId
|
|
523
|
+
}]
|
|
524
|
+
});
|
|
525
|
+
},
|
|
526
|
+
updateAccount: async (id, data) => {
|
|
527
|
+
return await updateWithHooks(data, [{
|
|
528
|
+
field: "id",
|
|
529
|
+
value: id
|
|
530
|
+
}], "account", void 0);
|
|
531
|
+
},
|
|
532
|
+
createVerificationValue: async (data) => {
|
|
533
|
+
const storageOption = getStorageOption(data.identifier, options.verification?.storeIdentifier);
|
|
534
|
+
const storedIdentifier = await processIdentifier(data.identifier, storageOption);
|
|
535
|
+
return await createWithHooks({
|
|
536
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
537
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
538
|
+
...data,
|
|
539
|
+
identifier: storedIdentifier
|
|
540
|
+
}, "verification", secondaryStorage ? {
|
|
541
|
+
async fn(verificationData) {
|
|
542
|
+
const ttl = getTTLSeconds(verificationData.expiresAt);
|
|
543
|
+
if (ttl > 0) await secondaryStorage.set(`verification:${storedIdentifier}`, JSON.stringify(verificationData), ttl);
|
|
544
|
+
return verificationData;
|
|
545
|
+
},
|
|
546
|
+
executeMainFn: options.verification?.storeInDatabase
|
|
547
|
+
} : void 0);
|
|
548
|
+
},
|
|
549
|
+
findVerificationValue: async (identifier) => {
|
|
550
|
+
const storageOption = getStorageOption(identifier, options.verification?.storeIdentifier);
|
|
551
|
+
const storedIdentifier = await processIdentifier(identifier, storageOption);
|
|
552
|
+
if (secondaryStorage) {
|
|
553
|
+
const cached = await secondaryStorage.get(`verification:${storedIdentifier}`);
|
|
554
|
+
if (cached) {
|
|
555
|
+
const parsed = safeJSONParse(cached);
|
|
556
|
+
if (parsed) return parsed;
|
|
557
|
+
}
|
|
558
|
+
if (storageOption && storageOption !== "plain") {
|
|
559
|
+
const plainCached = await secondaryStorage.get(`verification:${identifier}`);
|
|
560
|
+
if (plainCached) {
|
|
561
|
+
const parsed = safeJSONParse(plainCached);
|
|
562
|
+
if (parsed) return parsed;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (!options.verification?.storeInDatabase) return null;
|
|
566
|
+
}
|
|
567
|
+
const currentAdapter = await getCurrentAdapter(adapter);
|
|
568
|
+
async function findByIdentifier(id) {
|
|
569
|
+
return currentAdapter.findMany({
|
|
570
|
+
model: "verification",
|
|
571
|
+
where: [{
|
|
572
|
+
field: "identifier",
|
|
573
|
+
value: id
|
|
574
|
+
}],
|
|
575
|
+
sortBy: {
|
|
576
|
+
field: "createdAt",
|
|
577
|
+
direction: "desc"
|
|
578
|
+
},
|
|
579
|
+
limit: 1
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
let verification = await findByIdentifier(storedIdentifier);
|
|
583
|
+
if (!verification.length && storageOption && storageOption !== "plain") verification = await findByIdentifier(identifier);
|
|
584
|
+
if (!options.verification?.disableCleanup) await deleteManyWithHooks([{
|
|
585
|
+
field: "expiresAt",
|
|
586
|
+
value: /* @__PURE__ */ new Date(),
|
|
587
|
+
operator: "lt"
|
|
588
|
+
}], "verification", void 0);
|
|
589
|
+
return verification[0] || null;
|
|
590
|
+
},
|
|
591
|
+
deleteVerificationValue: async (id) => {
|
|
592
|
+
if (!secondaryStorage || options.verification?.storeInDatabase) await deleteWithHooks([{
|
|
593
|
+
field: "id",
|
|
594
|
+
value: id
|
|
595
|
+
}], "verification", void 0);
|
|
596
|
+
},
|
|
597
|
+
deleteVerificationByIdentifier: async (identifier) => {
|
|
598
|
+
const storedIdentifier = await processIdentifier(identifier, getStorageOption(identifier, options.verification?.storeIdentifier));
|
|
599
|
+
if (secondaryStorage) await secondaryStorage.delete(`verification:${storedIdentifier}`);
|
|
600
|
+
if (!secondaryStorage || options.verification?.storeInDatabase) await deleteWithHooks([{
|
|
601
|
+
field: "identifier",
|
|
602
|
+
value: storedIdentifier
|
|
603
|
+
}], "verification", void 0);
|
|
604
|
+
},
|
|
605
|
+
updateVerificationValue: async (id, data) => {
|
|
606
|
+
return await updateWithHooks(data, [{
|
|
607
|
+
field: "id",
|
|
608
|
+
value: id
|
|
609
|
+
}], "verification", void 0);
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
//#endregion
|
|
615
|
+
export { createInternalAdapter };
|
|
616
|
+
//# sourceMappingURL=internal-adapter.mjs.map
|