@revealui/auth 0.0.1-pre.0
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 +202 -0
- package/dist/better-auth/adapter/__tests__/transform.test.js +213 -0
- package/dist/better-auth/adapter/__tests__/transform.test.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/biome.d.js +2 -0
- package/dist/better-auth/adapter/generate-schema/biome.d.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/generate-schema-builder.d.ts +5 -0
- package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js +482 -0
- package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/get-payload-schema.d.ts +1 -0
- package/dist/better-auth/adapter/generate-schema/get-payload-schema.js +42 -0
- package/dist/better-auth/adapter/generate-schema/get-payload-schema.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/index.d.ts +4 -0
- package/dist/better-auth/adapter/generate-schema/index.js +19 -0
- package/dist/better-auth/adapter/generate-schema/index.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/utils.d.ts +2 -0
- package/dist/better-auth/adapter/generate-schema/utils.js +20 -0
- package/dist/better-auth/adapter/generate-schema/utils.js.map +1 -0
- package/dist/better-auth/adapter/index.d.ts +15 -0
- package/dist/better-auth/adapter/index.js +731 -0
- package/dist/better-auth/adapter/index.js.map +1 -0
- package/dist/better-auth/adapter/tests/adapter.test.js +174 -0
- package/dist/better-auth/adapter/tests/adapter.test.js.map +1 -0
- package/dist/better-auth/adapter/tests/base-collections-tests.js +575 -0
- package/dist/better-auth/adapter/tests/base-collections-tests.js.map +1 -0
- package/dist/better-auth/adapter/tests/dev/index.js +117 -0
- package/dist/better-auth/adapter/tests/dev/index.js.map +1 -0
- package/dist/better-auth/adapter/tests/dev/migrate.js +26 -0
- package/dist/better-auth/adapter/tests/dev/migrate.js.map +1 -0
- package/dist/better-auth/adapter/tests/dev/migrations/20250423_232936_init.js +218 -0
- package/dist/better-auth/adapter/tests/dev/migrations/20250423_232936_init.js.map +1 -0
- package/dist/better-auth/adapter/tests/dev/schema.js +160 -0
- package/dist/better-auth/adapter/tests/dev/schema.js.map +1 -0
- package/dist/better-auth/adapter/tests/plugins-tests.js +2 -0
- package/dist/better-auth/adapter/tests/plugins-tests.js.map +1 -0
- package/dist/better-auth/adapter/transform/index.d.ts +27 -0
- package/dist/better-auth/adapter/transform/index.js +664 -0
- package/dist/better-auth/adapter/transform/index.js.map +1 -0
- package/dist/better-auth/adapter/types.d.ts +10 -0
- package/dist/better-auth/adapter/types.js +3 -0
- package/dist/better-auth/adapter/types.js.map +1 -0
- package/dist/better-auth/generated-types.d.ts +285 -0
- package/dist/better-auth/index.d.ts +3 -0
- package/dist/better-auth/index.js +5 -0
- package/dist/better-auth/index.js.map +1 -0
- package/dist/better-auth/plugin/__tests__/plugin.test.js +162 -0
- package/dist/better-auth/plugin/__tests__/plugin.test.js.map +1 -0
- package/dist/better-auth/plugin/constants.d.ts +220 -0
- package/dist/better-auth/plugin/constants.js +249 -0
- package/dist/better-auth/plugin/constants.js.map +1 -0
- package/dist/better-auth/plugin/helpers/check-plugin-exists.d.ts +12 -0
- package/dist/better-auth/plugin/helpers/check-plugin-exists.js +14 -0
- package/dist/better-auth/plugin/helpers/check-plugin-exists.js.map +1 -0
- package/dist/better-auth/plugin/helpers/generate-verify-email-url.d.ts +29 -0
- package/dist/better-auth/plugin/helpers/generate-verify-email-url.js +46 -0
- package/dist/better-auth/plugin/helpers/generate-verify-email-url.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-admin-access.d.ts +7 -0
- package/dist/better-auth/plugin/helpers/get-admin-access.js +22 -0
- package/dist/better-auth/plugin/helpers/get-admin-access.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-all-roles.d.ts +5 -0
- package/dist/better-auth/plugin/helpers/get-all-roles.js +20 -0
- package/dist/better-auth/plugin/helpers/get-all-roles.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-better-auth-schema.d.ts +18 -0
- package/dist/better-auth/plugin/helpers/get-better-auth-schema.js +70 -0
- package/dist/better-auth/plugin/helpers/get-better-auth-schema.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-collection-slug.d.ts +5 -0
- package/dist/better-auth/plugin/helpers/get-collection-slug.js +20 -0
- package/dist/better-auth/plugin/helpers/get-collection-slug.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-collection.d.ts +15 -0
- package/dist/better-auth/plugin/helpers/get-collection.js +29 -0
- package/dist/better-auth/plugin/helpers/get-collection.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-ip.d.ts +2 -0
- package/dist/better-auth/plugin/helpers/get-ip.js +31 -0
- package/dist/better-auth/plugin/helpers/get-ip.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-signed-cookie.d.ts +2 -0
- package/dist/better-auth/plugin/helpers/get-signed-cookie.js +65 -0
- package/dist/better-auth/plugin/helpers/get-signed-cookie.js.map +1 -0
- package/dist/better-auth/plugin/helpers/index.d.ts +1 -0
- package/dist/better-auth/plugin/helpers/index.js +3 -0
- package/dist/better-auth/plugin/helpers/index.js.map +1 -0
- package/dist/better-auth/plugin/helpers/prepare-session-data.d.ts +59 -0
- package/dist/better-auth/plugin/helpers/prepare-session-data.js +49 -0
- package/dist/better-auth/plugin/helpers/prepare-session-data.js.map +1 -0
- package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.d.ts +20 -0
- package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.js +67 -0
- package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.js.map +1 -0
- package/dist/better-auth/plugin/index.d.ts +11 -0
- package/dist/better-auth/plugin/index.js +125 -0
- package/dist/better-auth/plugin/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.d.ts +12 -0
- package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.js +87 -0
- package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.js +60 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/index.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/index.js +154 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.d.ts +5 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.js +11 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.js +8 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.d.ts +6 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.js +119 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/api-keys.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/api-keys.js +177 -0
- package/dist/better-auth/plugin/lib/build-collections/api-keys.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/device-code.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/device-code.js +50 -0
- package/dist/better-auth/plugin/lib/build-collections/device-code.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/index.d.ts +10 -0
- package/dist/better-auth/plugin/lib/build-collections/index.js +73 -0
- package/dist/better-auth/plugin/lib/build-collections/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/invitations.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/invitations.js +94 -0
- package/dist/better-auth/plugin/lib/build-collections/invitations.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/jwks.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/jwks.js +59 -0
- package/dist/better-auth/plugin/lib/build-collections/jwks.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/members.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/members.js +73 -0
- package/dist/better-auth/plugin/lib/build-collections/members.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.js +107 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-applications.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-applications.js +118 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-applications.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-consents.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-consents.js +89 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-consents.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/organizations.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/organizations.js +70 -0
- package/dist/better-auth/plugin/lib/build-collections/organizations.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/passkeys.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/passkeys.js +115 -0
- package/dist/better-auth/plugin/lib/build-collections/passkeys.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/sessions.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/sessions.js +170 -0
- package/dist/better-auth/plugin/lib/build-collections/sessions.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/sso-providers.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/sso-providers.js +81 -0
- package/dist/better-auth/plugin/lib/build-collections/sso-providers.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/subscriptions.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/subscriptions.js +111 -0
- package/dist/better-auth/plugin/lib/build-collections/subscriptions.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/team-members.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/team-members.js +57 -0
- package/dist/better-auth/plugin/lib/build-collections/team-members.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/teams.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/teams.js +76 -0
- package/dist/better-auth/plugin/lib/build-collections/teams.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/two-factors.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/two-factors.js +67 -0
- package/dist/better-auth/plugin/lib/build-collections/two-factors.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.d.ts +7 -0
- package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.js +53 -0
- package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.d.ts +11 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.js +75 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.d.ts +4 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.js +6 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.js +115 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.js +64 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.js +80 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.d.ts +6 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.js +79 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.js +82 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.js +54 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.d.ts +6 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.js +15 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.d.ts +6 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.js +8 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.js +17 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.js +91 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/index.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/users/index.js +341 -0
- package/dist/better-auth/plugin/lib/build-collections/users/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.d.ts +15 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.js +24 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.d.ts +10 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.js +67 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.d.ts +9 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.js +94 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.d.ts +7 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.js +35 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.d.ts +12 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.js +25 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.d.ts +14 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.js +67 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.d.ts +20 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.js +98 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/verifications.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/verifications.js +87 -0
- package/dist/better-auth/plugin/lib/build-collections/verifications.js.map +1 -0
- package/dist/better-auth/plugin/lib/get-payload-auth.d.ts +5 -0
- package/dist/better-auth/plugin/lib/get-payload-auth.js +9 -0
- package/dist/better-auth/plugin/lib/get-payload-auth.js.map +1 -0
- package/dist/better-auth/plugin/lib/init-better-auth.d.ts +7 -0
- package/dist/better-auth/plugin/lib/init-better-auth.js +46 -0
- package/dist/better-auth/plugin/lib/init-better-auth.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.js +9 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.js +10 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.js +8 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.d.ts +10 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.js +156 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.js +18 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.js +34 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.js +11 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.js +10 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.js +11 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.d.ts +7 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.js +23 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.d.ts +25 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.js +62 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.d.ts +9 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.js +47 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.d.ts +15 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.js +42 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.d.ts +9 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.js +63 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.js.map +1 -0
- package/dist/better-auth/plugin/lib/set-login-methods.d.ts +4 -0
- package/dist/better-auth/plugin/lib/set-login-methods.js +14 -0
- package/dist/better-auth/plugin/lib/set-login-methods.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/admin-buttons/index.d.ts +9 -0
- package/dist/better-auth/plugin/payload/components/admin-buttons/index.js +143 -0
- package/dist/better-auth/plugin/payload/components/admin-buttons/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/admin-invite-button/index.d.ts +10 -0
- package/dist/better-auth/plugin/payload/components/admin-invite-button/index.js +219 -0
- package/dist/better-auth/plugin/payload/components/admin-invite-button/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/logout-button.d.ts +4 -0
- package/dist/better-auth/plugin/payload/components/logout-button.js +24 -0
- package/dist/better-auth/plugin/payload/components/logout-button.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/add-button.d.ts +8 -0
- package/dist/better-auth/plugin/payload/components/passkeys/add-button.js +117 -0
- package/dist/better-auth/plugin/payload/components/passkeys/add-button.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/client.d.ts +3 -0
- package/dist/better-auth/plugin/payload/components/passkeys/client.js +66 -0
- package/dist/better-auth/plugin/payload/components/passkeys/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/index.d.ts +4 -0
- package/dist/better-auth/plugin/payload/components/passkeys/index.js +52 -0
- package/dist/better-auth/plugin/payload/components/passkeys/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/list.d.ts +8 -0
- package/dist/better-auth/plugin/payload/components/passkeys/list.js +57 -0
- package/dist/better-auth/plugin/payload/components/passkeys/list.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/types.d.ts +22 -0
- package/dist/better-auth/plugin/payload/components/passkeys/types.js +3 -0
- package/dist/better-auth/plugin/payload/components/passkeys/types.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/rsc-redirect.d.ts +6 -0
- package/dist/better-auth/plugin/payload/components/rsc-redirect.js +7 -0
- package/dist/better-auth/plugin/payload/components/rsc-redirect.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.d.ts +15 -0
- package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.js +157 -0
- package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/token-field.d.ts +4 -0
- package/dist/better-auth/plugin/payload/components/token-field.js +31 -0
- package/dist/better-auth/plugin/payload/components/token-field.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/two-factor-auth/index.d.ts +8 -0
- package/dist/better-auth/plugin/payload/components/two-factor-auth/index.js +300 -0
- package/dist/better-auth/plugin/payload/components/two-factor-auth/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/exports/client.d.ts +6 -0
- package/dist/better-auth/plugin/payload/exports/client.js +8 -0
- package/dist/better-auth/plugin/payload/exports/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/exports/rsc.d.ts +8 -0
- package/dist/better-auth/plugin/payload/exports/rsc.js +10 -0
- package/dist/better-auth/plugin/payload/exports/rsc.js.map +1 -0
- package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.d.ts +2 -0
- package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.js +9 -0
- package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.js.map +1 -0
- package/dist/better-auth/plugin/payload/utils/get-safe-redirect.d.ts +1 -0
- package/dist/better-auth/plugin/payload/utils/get-safe-redirect.js +22 -0
- package/dist/better-auth/plugin/payload/utils/get-safe-redirect.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/admin-login/client.d.ts +19 -0
- package/dist/better-auth/plugin/payload/views/admin-login/client.js +226 -0
- package/dist/better-auth/plugin/payload/views/admin-login/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/admin-login/index.d.ts +10 -0
- package/dist/better-auth/plugin/payload/views/admin-login/index.js +150 -0
- package/dist/better-auth/plugin/payload/views/admin-login/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/client.d.ts +16 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/client.js +299 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/index.d.ts +9 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/index.js +104 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/client.d.ts +7 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/client.js +119 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/index.d.ts +8 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/index.js +78 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/reset-password/client.d.ts +10 -0
- package/dist/better-auth/plugin/payload/views/reset-password/client.js +144 -0
- package/dist/better-auth/plugin/payload/views/reset-password/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/reset-password/index.d.ts +8 -0
- package/dist/better-auth/plugin/payload/views/reset-password/index.js +96 -0
- package/dist/better-auth/plugin/payload/views/reset-password/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/client.d.ts +6 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/client.js +96 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/index.d.ts +9 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/index.js +56 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/index.js.map +1 -0
- package/dist/better-auth/plugin/types.d.ts +429 -0
- package/dist/better-auth/plugin/types.js +3 -0
- package/dist/better-auth/plugin/types.js.map +1 -0
- package/dist/better-auth/plugin/utils/set.d.ts +39 -0
- package/dist/better-auth/plugin/utils/set.js +103 -0
- package/dist/better-auth/plugin/utils/set.js.map +1 -0
- package/dist/better-auth/scripts/generate-types.d.ts +1 -0
- package/dist/better-auth/scripts/generate-types.js +234 -0
- package/dist/better-auth/scripts/generate-types.js.map +1 -0
- package/dist/better-auth/types.d.ts +2 -0
- package/dist/better-auth/types.js +4 -0
- package/dist/better-auth/types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/components/icons.d.ts +7 -0
- package/dist/shared/components/icons.js +442 -0
- package/dist/shared/components/icons.js.map +1 -0
- package/dist/shared/components/logo.d.ts +3 -0
- package/dist/shared/components/logo.js +24 -0
- package/dist/shared/components/logo.js.map +1 -0
- package/dist/shared/form/components/submit.d.ts +7 -0
- package/dist/shared/form/components/submit.js +16 -0
- package/dist/shared/form/components/submit.js.map +1 -0
- package/dist/shared/form/fields/text-field.d.ts +8 -0
- package/dist/shared/form/fields/text-field.js +37 -0
- package/dist/shared/form/fields/text-field.js.map +1 -0
- package/dist/shared/form/index.d.ts +4 -0
- package/dist/shared/form/index.js +8 -0
- package/dist/shared/form/index.js.map +1 -0
- package/dist/shared/form/ui/header/index.d.ts +8 -0
- package/dist/shared/form/ui/header/index.js +24 -0
- package/dist/shared/form/ui/header/index.js.map +1 -0
- package/dist/shared/form/ui/index.d.ts +31 -0
- package/dist/shared/form/ui/index.js +57 -0
- package/dist/shared/form/ui/index.js.map +1 -0
- package/dist/shared/form/validation.d.ts +51 -0
- package/dist/shared/form/validation.js +127 -0
- package/dist/shared/form/validation.js.map +1 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/payload/fields/field-copy-button/index.d.ts +3 -0
- package/dist/shared/payload/fields/field-copy-button/index.js +38 -0
- package/dist/shared/payload/fields/field-copy-button/index.js.map +1 -0
- package/dist/shared/payload/fields/generate-uuid-button/index.d.ts +3 -0
- package/dist/shared/payload/fields/generate-uuid-button/index.js +26 -0
- package/dist/shared/payload/fields/generate-uuid-button/index.js.map +1 -0
- package/dist/shared/payload/fields/index.d.ts +2 -0
- package/dist/shared/payload/fields/index.js +4 -0
- package/dist/shared/payload/fields/index.js.map +1 -0
- package/dist/shared/utils/regex.d.ts +2 -0
- package/dist/shared/utils/regex.js +4 -0
- package/dist/shared/utils/regex.js.map +1 -0
- package/dist/shared/utils/try-catch.d.ts +11 -0
- package/dist/shared/utils/try-catch.js +17 -0
- package/dist/shared/utils/try-catch.js.map +1 -0
- package/dist/shared/utils/value-or-default.d.ts +9 -0
- package/dist/shared/utils/value-or-default.js +12 -0
- package/dist/shared/utils/value-or-default.js.map +1 -0
- package/package.json +122 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { baModelFieldKeys, baModelKey, baseSlugs, defaults, supportedBAPluginIds } from "@/better-auth/plugin/constants";
|
|
2
|
+
import { set } from "../../utils/set";
|
|
3
|
+
import { getSchemaCollectionSlug, getSchemaFieldName } from "../build-collections/utils/collection-schema";
|
|
4
|
+
import { configureAdminPlugin } from "./admin-plugin";
|
|
5
|
+
import { configureApiKeyPlugin } from "./api-key-plugin";
|
|
6
|
+
import { configureDeviceAuthorizationPlugin } from "./device-authorization-plugin";
|
|
7
|
+
import { configureOidcPlugin } from "./oidc-plugin";
|
|
8
|
+
import { configureOrganizationPlugin } from "./organizations-plugin";
|
|
9
|
+
import { configurePasskeyPlugin } from "./passkey-plugin";
|
|
10
|
+
import { configureSsoPlugin } from "./sso-plugin";
|
|
11
|
+
import { configureTwoFactorPlugin } from "./two-factor-plugin";
|
|
12
|
+
import { ensurePasswordSetBeforeUserCreate } from "./utils/ensure-password-set-before-create";
|
|
13
|
+
import { hashPassword, verifyPassword } from "./utils/password";
|
|
14
|
+
import { requireAdminInviteForSignUpMiddleware } from "./utils/require-admin-invite-for-sign-up-middleware";
|
|
15
|
+
import { saveToJwtMiddleware } from "./utils/save-to-jwt-middleware";
|
|
16
|
+
import { useAdminInviteAfterEmailSignUpMiddleware } from "./utils/use-admin-invite-after-email-sign-up-middleware";
|
|
17
|
+
/**
|
|
18
|
+
* Sanitizes the BetterAuth options
|
|
19
|
+
*/ export function sanitizeBetterAuthOptions({ config, pluginOptions, resolvedSchemas }) {
|
|
20
|
+
const betterAuthOptions = {
|
|
21
|
+
...pluginOptions.betterAuthOptions ?? {}
|
|
22
|
+
};
|
|
23
|
+
// Ensure required option groups are always defined to satisfy exactOptionalPropertyTypes
|
|
24
|
+
betterAuthOptions.user = betterAuthOptions.user || {};
|
|
25
|
+
betterAuthOptions.session = betterAuthOptions.session || {};
|
|
26
|
+
betterAuthOptions.account = betterAuthOptions.account || {};
|
|
27
|
+
betterAuthOptions.verification = betterAuthOptions.verification || {};
|
|
28
|
+
betterAuthOptions.advanced = betterAuthOptions.advanced || {};
|
|
29
|
+
const userCollectionSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.user);
|
|
30
|
+
const adminInvitationCollectionSlug = pluginOptions.adminInvitations?.slug ?? baseSlugs.adminInvitations;
|
|
31
|
+
set(betterAuthOptions, `${baModelKey.user}.modelName`, userCollectionSlug);
|
|
32
|
+
set(betterAuthOptions, `${baModelKey.user}.additionalFields.role`, {
|
|
33
|
+
defaultValue: pluginOptions.users?.defaultRole || defaults.userRole,
|
|
34
|
+
input: false,
|
|
35
|
+
type: 'string'
|
|
36
|
+
});
|
|
37
|
+
const baseModels = [
|
|
38
|
+
baModelKey.account,
|
|
39
|
+
baModelKey.session,
|
|
40
|
+
baModelKey.verification
|
|
41
|
+
];
|
|
42
|
+
baseModels.forEach((model)=>set(betterAuthOptions, `${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model)));
|
|
43
|
+
set(betterAuthOptions, `${baModelKey.account}.fields.userId`, getSchemaFieldName(resolvedSchemas, baModelKey.account, baModelFieldKeys.account.userId));
|
|
44
|
+
set(betterAuthOptions, `${baModelKey.session}.fields.userId`, getSchemaFieldName(resolvedSchemas, baModelKey.session, baModelFieldKeys.session.userId));
|
|
45
|
+
set(betterAuthOptions, 'emailAndPassword.enabled', betterAuthOptions.emailAndPassword?.enabled ?? true);
|
|
46
|
+
// Configure password handling
|
|
47
|
+
if (betterAuthOptions.emailAndPassword?.enabled && !pluginOptions.disableDefaultPayloadAuth) {
|
|
48
|
+
betterAuthOptions.emailAndPassword.password = {
|
|
49
|
+
...betterAuthOptions.emailAndPassword.password || {},
|
|
50
|
+
hash: (password)=>hashPassword(password),
|
|
51
|
+
verify: ({ hash, password, salt })=>salt !== undefined ? verifyPassword({
|
|
52
|
+
hash,
|
|
53
|
+
password,
|
|
54
|
+
salt
|
|
55
|
+
}) : verifyPassword({
|
|
56
|
+
hash,
|
|
57
|
+
password
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Handle admin invite for sign up
|
|
62
|
+
if (pluginOptions.requireAdminInviteForSignUp) {
|
|
63
|
+
betterAuthOptions.socialProviders = betterAuthOptions.socialProviders || {};
|
|
64
|
+
betterAuthOptions.socialProviders = Object.fromEntries(Object.entries(betterAuthOptions.socialProviders).map(([provider, config])=>[
|
|
65
|
+
provider,
|
|
66
|
+
// Using Record<string, unknown> because provider config structure varies by provider type and cannot be strictly typed
|
|
67
|
+
{
|
|
68
|
+
...config ?? {},
|
|
69
|
+
disableImplicitSignUp: true
|
|
70
|
+
}
|
|
71
|
+
]));
|
|
72
|
+
requireAdminInviteForSignUpMiddleware({
|
|
73
|
+
options: betterAuthOptions,
|
|
74
|
+
pluginOptions
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks -- This is not a React hook, just misnamed (starts with "use")
|
|
78
|
+
useAdminInviteAfterEmailSignUpMiddleware({
|
|
79
|
+
adminInvitationCollectionSlug,
|
|
80
|
+
options: betterAuthOptions,
|
|
81
|
+
userCollectionSlug
|
|
82
|
+
});
|
|
83
|
+
// Handle verification email blocking
|
|
84
|
+
if (pluginOptions.users?.blockFirstBetterAuthVerificationEmail && !pluginOptions.disableDefaultPayloadAuth) {
|
|
85
|
+
const originalSendEmail = betterAuthOptions?.emailVerification?.sendVerificationEmail;
|
|
86
|
+
if (typeof originalSendEmail === 'function') {
|
|
87
|
+
betterAuthOptions.emailVerification = betterAuthOptions.emailVerification ?? {};
|
|
88
|
+
betterAuthOptions.emailVerification.sendVerificationEmail = async (...args)=>{
|
|
89
|
+
try {
|
|
90
|
+
const [data] = args;
|
|
91
|
+
const timeSinceCreation = new Date().getTime() - new Date(data.user.createdAt).getTime();
|
|
92
|
+
// Skip if user was created less than a minute ago (rely on Payload's email)
|
|
93
|
+
if (timeSinceCreation >= 60000) {
|
|
94
|
+
await originalSendEmail(...args);
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
// Use payload logger if available in context
|
|
98
|
+
const [, request] = args;
|
|
99
|
+
// Using Record<string, unknown> because BetterAuth middleware request structure varies by context and cannot be strictly typed
|
|
100
|
+
const payload = request?.payload;
|
|
101
|
+
if (payload?.logger) {
|
|
102
|
+
payload.logger.error('Error sending verification email', {
|
|
103
|
+
error: error instanceof Error ? error.message : String(error),
|
|
104
|
+
stack: error instanceof Error ? error.stack : undefined
|
|
105
|
+
});
|
|
106
|
+
} else {
|
|
107
|
+
console.error('Error sending verification email:', error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Ensure password is set before user creation
|
|
114
|
+
if (!pluginOptions.disableDefaultPayloadAuth) {
|
|
115
|
+
ensurePasswordSetBeforeUserCreate(betterAuthOptions);
|
|
116
|
+
}
|
|
117
|
+
// Process plugins
|
|
118
|
+
if (betterAuthOptions.plugins?.length) {
|
|
119
|
+
try {
|
|
120
|
+
// Filter to only supported plugins
|
|
121
|
+
const supportedPlugins = betterAuthOptions.plugins.filter((plugin)=>Object.values(supportedBAPluginIds).includes(plugin.id));
|
|
122
|
+
// Log warning for unsupported plugins
|
|
123
|
+
if (supportedPlugins.length !== betterAuthOptions.plugins.length) {
|
|
124
|
+
const unsupportedIds = betterAuthOptions.plugins.filter((p)=>!Object.values(supportedBAPluginIds).includes(p.id)).map((p)=>p.id).join(', ');
|
|
125
|
+
// Log warning for unsupported plugins - use console.warn as fallback since this runs during config initialization
|
|
126
|
+
console.warn(`Unsupported BetterAuth plugins: ${unsupportedIds}. Supported: ${Object.values(supportedBAPluginIds).join(', ')}`);
|
|
127
|
+
}
|
|
128
|
+
// Configure plugins by type
|
|
129
|
+
const pluginConfigurators = {
|
|
130
|
+
[supportedBAPluginIds.admin]: (p)=>configureAdminPlugin(p, pluginOptions),
|
|
131
|
+
[supportedBAPluginIds.apiKey]: (p)=>configureApiKeyPlugin(p, resolvedSchemas),
|
|
132
|
+
[supportedBAPluginIds.deviceAuthorization]: (p)=>configureDeviceAuthorizationPlugin(p, resolvedSchemas),
|
|
133
|
+
[supportedBAPluginIds.oidc]: (p)=>configureOidcPlugin(p, resolvedSchemas),
|
|
134
|
+
[supportedBAPluginIds.organization]: (p)=>configureOrganizationPlugin(p, resolvedSchemas),
|
|
135
|
+
[supportedBAPluginIds.passkey]: (p)=>configurePasskeyPlugin(p, resolvedSchemas),
|
|
136
|
+
[supportedBAPluginIds.sso]: (p)=>configureSsoPlugin(p, resolvedSchemas),
|
|
137
|
+
[supportedBAPluginIds.twoFactor]: (p)=>configureTwoFactorPlugin(p, resolvedSchemas)
|
|
138
|
+
};
|
|
139
|
+
supportedPlugins.forEach((plugin)=>{
|
|
140
|
+
const configurator = pluginConfigurators[plugin.id];
|
|
141
|
+
if (configurator) configurator(plugin);
|
|
142
|
+
});
|
|
143
|
+
betterAuthOptions.plugins = supportedPlugins;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
throw new Error(`Error sanitizing BetterAuth plugins: ${error}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
saveToJwtMiddleware({
|
|
149
|
+
config,
|
|
150
|
+
resolvedSchemas,
|
|
151
|
+
sanitizedOptions: betterAuthOptions
|
|
152
|
+
});
|
|
153
|
+
return betterAuthOptions;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/sanitize-better-auth-options/index.ts"],"sourcesContent":["import {\n baModelFieldKeys,\n baModelKey,\n baseSlugs,\n defaults,\n supportedBAPluginIds,\n} from '@/better-auth/plugin/constants';\n\nimport { set } from '../../utils/set';\nimport {\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from '../build-collections/utils/collection-schema';\nimport { configureAdminPlugin } from './admin-plugin';\nimport { configureApiKeyPlugin } from './api-key-plugin';\nimport { configureDeviceAuthorizationPlugin } from './device-authorization-plugin';\nimport { configureOidcPlugin } from './oidc-plugin';\nimport { configureOrganizationPlugin } from './organizations-plugin';\nimport { configurePasskeyPlugin } from './passkey-plugin';\nimport { configureSsoPlugin } from './sso-plugin';\nimport { configureTwoFactorPlugin } from './two-factor-plugin';\nimport { ensurePasswordSetBeforeUserCreate } from './utils/ensure-password-set-before-create';\nimport { hashPassword, verifyPassword } from './utils/password';\nimport { requireAdminInviteForSignUpMiddleware } from './utils/require-admin-invite-for-sign-up-middleware';\nimport { saveToJwtMiddleware } from './utils/save-to-jwt-middleware';\nimport { useAdminInviteAfterEmailSignUpMiddleware } from './utils/use-admin-invite-after-email-sign-up-middleware';\n\nimport type {\n BetterAuthPluginOptions,\n BetterAuthSchemas,\n SanitizedBetterAuthOptions,\n} from '@/better-auth/plugin/types';\n// BetterAuthPlugin type - using any for plugin type since better-auth doesn't export a specific type\ntype BetterAuthPluginType = any;\nimport type { Config, Payload } from 'payload';\n\n/**\n * Sanitizes the BetterAuth options\n */\nexport function sanitizeBetterAuthOptions({\n config,\n pluginOptions,\n resolvedSchemas,\n}: {\n config: Payload['config'] | Config | Promise<Payload['config'] | Config>;\n pluginOptions: BetterAuthPluginOptions;\n resolvedSchemas: BetterAuthSchemas;\n}): SanitizedBetterAuthOptions {\n const betterAuthOptions: Partial<SanitizedBetterAuthOptions> = {\n ...(pluginOptions.betterAuthOptions ?? {}),\n };\n\n // Ensure required option groups are always defined to satisfy exactOptionalPropertyTypes\n betterAuthOptions.user =\n betterAuthOptions.user || ({} as NonNullable<SanitizedBetterAuthOptions['user']>);\n betterAuthOptions.session =\n betterAuthOptions.session || ({} as NonNullable<SanitizedBetterAuthOptions['session']>);\n betterAuthOptions.account =\n betterAuthOptions.account || ({} as NonNullable<SanitizedBetterAuthOptions['account']>);\n betterAuthOptions.verification =\n betterAuthOptions.verification ||\n ({} as NonNullable<SanitizedBetterAuthOptions['verification']>);\n betterAuthOptions.advanced =\n betterAuthOptions.advanced || ({} as NonNullable<SanitizedBetterAuthOptions['advanced']>);\n\n const userCollectionSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.user);\n const adminInvitationCollectionSlug =\n pluginOptions.adminInvitations?.slug ?? baseSlugs.adminInvitations;\n\n set(betterAuthOptions, `${baModelKey.user}.modelName`, userCollectionSlug);\n set(betterAuthOptions, `${baModelKey.user}.additionalFields.role`, {\n defaultValue: pluginOptions.users?.defaultRole || defaults.userRole,\n input: false,\n type: 'string',\n });\n\n const baseModels = [baModelKey.account, baModelKey.session, baModelKey.verification] as const;\n baseModels.forEach(model =>\n set(betterAuthOptions, `${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model))\n );\n\n set(\n betterAuthOptions,\n `${baModelKey.account}.fields.userId`,\n getSchemaFieldName(resolvedSchemas, baModelKey.account, baModelFieldKeys.account.userId)\n );\n set(\n betterAuthOptions,\n `${baModelKey.session}.fields.userId`,\n getSchemaFieldName(resolvedSchemas, baModelKey.session, baModelFieldKeys.session.userId)\n );\n\n set(\n betterAuthOptions,\n 'emailAndPassword.enabled',\n betterAuthOptions.emailAndPassword?.enabled ?? true\n );\n\n // Configure password handling\n if (betterAuthOptions.emailAndPassword?.enabled && !pluginOptions.disableDefaultPayloadAuth) {\n betterAuthOptions.emailAndPassword.password = {\n ...(betterAuthOptions.emailAndPassword.password || {}),\n hash: (password: string) => hashPassword(password),\n verify: ({ hash, password, salt }: { hash: string; password: string; salt?: string }) =>\n salt !== undefined\n ? verifyPassword({ hash, password, salt })\n : verifyPassword({ hash, password }),\n };\n }\n\n // Handle admin invite for sign up\n if (pluginOptions.requireAdminInviteForSignUp) {\n betterAuthOptions.socialProviders = betterAuthOptions.socialProviders || {};\n betterAuthOptions.socialProviders = Object.fromEntries(\n Object.entries(betterAuthOptions.socialProviders).map(([provider, config]) => [\n provider,\n // Using Record<string, unknown> because provider config structure varies by provider type and cannot be strictly typed\n {\n ...((config ??\n {}) as unknown as /* Using Record<string, unknown> because provider config structure varies by provider type and cannot be strictly typed */ Record<\n string,\n unknown\n >),\n disableImplicitSignUp: true,\n },\n ])\n );\n requireAdminInviteForSignUpMiddleware({\n options: betterAuthOptions,\n pluginOptions,\n });\n }\n // eslint-disable-next-line react-hooks/rules-of-hooks -- This is not a React hook, just misnamed (starts with \"use\")\n useAdminInviteAfterEmailSignUpMiddleware({\n adminInvitationCollectionSlug,\n options: betterAuthOptions,\n userCollectionSlug,\n });\n\n // Handle verification email blocking\n if (\n pluginOptions.users?.blockFirstBetterAuthVerificationEmail &&\n !pluginOptions.disableDefaultPayloadAuth\n ) {\n const originalSendEmail = betterAuthOptions?.emailVerification?.sendVerificationEmail;\n if (typeof originalSendEmail === 'function') {\n betterAuthOptions.emailVerification = betterAuthOptions.emailVerification ?? {};\n betterAuthOptions.emailVerification.sendVerificationEmail = async (\n ...args: Parameters<typeof originalSendEmail>\n ) => {\n try {\n const [data] = args;\n const timeSinceCreation = new Date().getTime() - new Date(data.user.createdAt).getTime();\n // Skip if user was created less than a minute ago (rely on Payload's email)\n if (timeSinceCreation >= 60000) {\n await originalSendEmail(...args);\n }\n } catch (error) {\n // Use payload logger if available in context\n const [, request] = args;\n // Using Record<string, unknown> because BetterAuth middleware request structure varies by context and cannot be strictly typed\n const payload = (\n request as unknown as /* Using Record<string, unknown> because BetterAuth middleware request structure varies by context and cannot be strictly typed */ Record<\n string,\n unknown\n >\n )?.payload as Payload | undefined;\n if (payload?.logger) {\n payload.logger.error('Error sending verification email', {\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n });\n } else {\n console.error('Error sending verification email:', error);\n }\n }\n };\n }\n }\n\n // Ensure password is set before user creation\n if (!pluginOptions.disableDefaultPayloadAuth) {\n ensurePasswordSetBeforeUserCreate(betterAuthOptions);\n }\n\n // Process plugins\n if (betterAuthOptions.plugins?.length) {\n try {\n // Filter to only supported plugins\n const supportedPlugins = betterAuthOptions.plugins.filter((plugin: BetterAuthPluginType) =>\n Object.values(supportedBAPluginIds).includes(\n (plugin as { id: string })\n .id as unknown as (typeof supportedBAPluginIds)[keyof typeof supportedBAPluginIds]\n )\n );\n\n // Log warning for unsupported plugins\n if (supportedPlugins.length !== betterAuthOptions.plugins.length) {\n const unsupportedIds = betterAuthOptions.plugins\n .filter(\n (p: BetterAuthPluginType) =>\n !Object.values(supportedBAPluginIds).includes(\n (p as { id: string })\n .id as unknown as (typeof supportedBAPluginIds)[keyof typeof supportedBAPluginIds]\n )\n )\n .map((p: BetterAuthPluginType) => (p as { id: string }).id)\n .join(', ');\n\n // Log warning for unsupported plugins - use console.warn as fallback since this runs during config initialization\n\n console.warn(\n `Unsupported BetterAuth plugins: ${unsupportedIds}. Supported: ${Object.values(supportedBAPluginIds).join(', ')}`\n );\n }\n\n // Configure plugins by type\n const pluginConfigurators = {\n [supportedBAPluginIds.admin]: (p: BetterAuthPluginType) =>\n configureAdminPlugin(p, pluginOptions),\n [supportedBAPluginIds.apiKey]: (p: BetterAuthPluginType) =>\n configureApiKeyPlugin(p, resolvedSchemas),\n [supportedBAPluginIds.deviceAuthorization]: (p: BetterAuthPluginType) =>\n configureDeviceAuthorizationPlugin(p, resolvedSchemas),\n [supportedBAPluginIds.oidc]: (p: BetterAuthPluginType) =>\n configureOidcPlugin(p, resolvedSchemas),\n [supportedBAPluginIds.organization]: (p: BetterAuthPluginType) =>\n configureOrganizationPlugin(p, resolvedSchemas),\n [supportedBAPluginIds.passkey]: (p: BetterAuthPluginType) =>\n configurePasskeyPlugin(p, resolvedSchemas),\n [supportedBAPluginIds.sso]: (p: BetterAuthPluginType) =>\n configureSsoPlugin(p, resolvedSchemas),\n [supportedBAPluginIds.twoFactor]: (p: BetterAuthPluginType) =>\n configureTwoFactorPlugin(p, resolvedSchemas),\n };\n\n supportedPlugins.forEach((plugin: BetterAuthPluginType) => {\n const configurator =\n pluginConfigurators[(plugin as { id: string }).id as keyof typeof pluginConfigurators];\n if (configurator) configurator(plugin);\n });\n\n betterAuthOptions.plugins = supportedPlugins;\n } catch (error) {\n throw new Error(`Error sanitizing BetterAuth plugins: ${error}`);\n }\n }\n\n saveToJwtMiddleware({\n config,\n resolvedSchemas,\n sanitizedOptions: betterAuthOptions,\n });\n\n return betterAuthOptions as SanitizedBetterAuthOptions;\n}\n"],"names":["baModelFieldKeys","baModelKey","baseSlugs","defaults","supportedBAPluginIds","set","getSchemaCollectionSlug","getSchemaFieldName","configureAdminPlugin","configureApiKeyPlugin","configureDeviceAuthorizationPlugin","configureOidcPlugin","configureOrganizationPlugin","configurePasskeyPlugin","configureSsoPlugin","configureTwoFactorPlugin","ensurePasswordSetBeforeUserCreate","hashPassword","verifyPassword","requireAdminInviteForSignUpMiddleware","saveToJwtMiddleware","useAdminInviteAfterEmailSignUpMiddleware","sanitizeBetterAuthOptions","config","pluginOptions","resolvedSchemas","betterAuthOptions","user","session","account","verification","advanced","userCollectionSlug","adminInvitationCollectionSlug","adminInvitations","slug","defaultValue","users","defaultRole","userRole","input","type","baseModels","forEach","model","userId","emailAndPassword","enabled","disableDefaultPayloadAuth","password","hash","verify","salt","undefined","requireAdminInviteForSignUp","socialProviders","Object","fromEntries","entries","map","provider","disableImplicitSignUp","options","blockFirstBetterAuthVerificationEmail","originalSendEmail","emailVerification","sendVerificationEmail","args","data","timeSinceCreation","Date","getTime","createdAt","error","request","payload","logger","Error","message","String","stack","console","plugins","length","supportedPlugins","filter","plugin","values","includes","id","unsupportedIds","p","join","warn","pluginConfigurators","admin","apiKey","deviceAuthorization","oidc","organization","passkey","sso","twoFactor","configurator","sanitizedOptions"],"mappings":"AAAA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,SAAS,EACTC,QAAQ,EACRC,oBAAoB,QACf,iCAAiC;AAExC,SAASC,GAAG,QAAQ,kBAAkB;AACtC,SACEC,uBAAuB,EACvBC,kBAAkB,QACb,+CAA+C;AACtD,SAASC,oBAAoB,QAAQ,iBAAiB;AACtD,SAASC,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,kCAAkC,QAAQ,gCAAgC;AACnF,SAASC,mBAAmB,QAAQ,gBAAgB;AACpD,SAASC,2BAA2B,QAAQ,yBAAyB;AACrE,SAASC,sBAAsB,QAAQ,mBAAmB;AAC1D,SAASC,kBAAkB,QAAQ,eAAe;AAClD,SAASC,wBAAwB,QAAQ,sBAAsB;AAC/D,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,aAAajB;YACjC;YAEA5D,kBAAkBwD,OAAO,GAAGE;QAC9B,EAAE,OAAOX,OAAO;YACd,MAAM,IAAII,MAAM,CAAC,qCAAqC,EAAEJ,OAAO;QACjE;IACF;IAEArD,oBAAoB;QAClBG;QACAE;QACA+E,kBAAkB9E;IACpB;IAEA,OAAOA;AACT"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { baModelFieldKeys, baModelKey } from "@/better-auth/plugin/constants";
|
|
2
|
+
import { set } from "../../utils/set";
|
|
3
|
+
import { getSchemaCollectionSlug, getSchemaFieldName } from "../build-collections/utils/collection-schema";
|
|
4
|
+
export function configureOidcPlugin(plugin, resolvedSchemas) {
|
|
5
|
+
const models = [
|
|
6
|
+
baModelKey.oauthApplication,
|
|
7
|
+
baModelKey.oauthAccessToken,
|
|
8
|
+
baModelKey.oauthConsent
|
|
9
|
+
];
|
|
10
|
+
models.forEach((model)=>set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model)));
|
|
11
|
+
set(plugin, `schema.${baModelKey.oauthApplication}.fields.userId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.oauthApplication, baModelFieldKeys.oauthApplication.userId));
|
|
12
|
+
set(plugin, `schema.${baModelKey.oauthAccessToken}.fields.userId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.oauthAccessToken, baModelFieldKeys.oauthAccessToken.userId));
|
|
13
|
+
set(plugin, `schema.${baModelKey.oauthAccessToken}.fields.clientId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.oauthAccessToken, baModelFieldKeys.oauthAccessToken.clientId));
|
|
14
|
+
set(plugin, `schema.${baModelKey.oauthConsent}.fields.userId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.oauthConsent, baModelFieldKeys.oauthConsent.userId));
|
|
15
|
+
set(plugin, `schema.${baModelKey.oauthConsent}.fields.clientId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.oauthConsent, baModelFieldKeys.oauthConsent.clientId));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=oidc-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.ts"],"sourcesContent":["import { baModelFieldKeys, baModelKey } from '@/better-auth/plugin/constants';\nimport type { BetterAuthSchemas } from '@/better-auth/types';\nimport { set } from '../../utils/set';\nimport {\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from '../build-collections/utils/collection-schema';\n\nexport function configureOidcPlugin(plugin: any, resolvedSchemas: BetterAuthSchemas): void {\n const models = [\n baModelKey.oauthApplication,\n baModelKey.oauthAccessToken,\n baModelKey.oauthConsent,\n ] as const;\n\n models.forEach(model =>\n set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model))\n );\n\n set(\n plugin,\n `schema.${baModelKey.oauthApplication}.fields.userId.fieldName`,\n getSchemaFieldName(\n resolvedSchemas,\n baModelKey.oauthApplication,\n baModelFieldKeys.oauthApplication.userId\n )\n );\n\n set(\n plugin,\n `schema.${baModelKey.oauthAccessToken}.fields.userId.fieldName`,\n getSchemaFieldName(\n resolvedSchemas,\n baModelKey.oauthAccessToken,\n baModelFieldKeys.oauthAccessToken.userId\n )\n );\n set(\n plugin,\n `schema.${baModelKey.oauthAccessToken}.fields.clientId.fieldName`,\n getSchemaFieldName(\n resolvedSchemas,\n baModelKey.oauthAccessToken,\n baModelFieldKeys.oauthAccessToken.clientId\n )\n );\n\n set(\n plugin,\n `schema.${baModelKey.oauthConsent}.fields.userId.fieldName`,\n getSchemaFieldName(\n resolvedSchemas,\n baModelKey.oauthConsent,\n baModelFieldKeys.oauthConsent.userId\n )\n );\n set(\n plugin,\n `schema.${baModelKey.oauthConsent}.fields.clientId.fieldName`,\n getSchemaFieldName(\n resolvedSchemas,\n baModelKey.oauthConsent,\n baModelFieldKeys.oauthConsent.clientId\n )\n );\n}\n"],"names":["baModelFieldKeys","baModelKey","set","getSchemaCollectionSlug","getSchemaFieldName","configureOidcPlugin","plugin","resolvedSchemas","models","oauthApplication","oauthAccessToken","oauthConsent","forEach","model","userId","clientId"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,iCAAiC;AAE9E,SAASC,GAAG,QAAQ,kBAAkB;AACtC,SACEC,uBAAuB,EACvBC,kBAAkB,QACb,+CAA+C;AAEtD,OAAO,SAASC,oBAAoBC,MAAW,EAAEC,eAAkC;IACjF,MAAMC,SAAS;QACbP,WAAWQ,gBAAgB;QAC3BR,WAAWS,gBAAgB;QAC3BT,WAAWU,YAAY;KACxB;IAEDH,OAAOI,OAAO,CAACC,CAAAA,QACbX,IAAII,QAAQ,CAAC,OAAO,EAAEO,MAAM,UAAU,CAAC,EAAEV,wBAAwBI,iBAAiBM;IAGpFX,IACEI,QACA,CAAC,OAAO,EAAEL,WAAWQ,gBAAgB,CAAC,wBAAwB,CAAC,EAC/DL,mBACEG,iBACAN,WAAWQ,gBAAgB,EAC3BT,iBAAiBS,gBAAgB,CAACK,MAAM;IAI5CZ,IACEI,QACA,CAAC,OAAO,EAAEL,WAAWS,gBAAgB,CAAC,wBAAwB,CAAC,EAC/DN,mBACEG,iBACAN,WAAWS,gBAAgB,EAC3BV,iBAAiBU,gBAAgB,CAACI,MAAM;IAG5CZ,IACEI,QACA,CAAC,OAAO,EAAEL,WAAWS,gBAAgB,CAAC,0BAA0B,CAAC,EACjEN,mBACEG,iBACAN,WAAWS,gBAAgB,EAC3BV,iBAAiBU,gBAAgB,CAACK,QAAQ;IAI9Cb,IACEI,QACA,CAAC,OAAO,EAAEL,WAAWU,YAAY,CAAC,wBAAwB,CAAC,EAC3DP,mBACEG,iBACAN,WAAWU,YAAY,EACvBX,iBAAiBW,YAAY,CAACG,MAAM;IAGxCZ,IACEI,QACA,CAAC,OAAO,EAAEL,WAAWU,YAAY,CAAC,0BAA0B,CAAC,EAC7DP,mBACEG,iBACAN,WAAWU,YAAY,EACvBX,iBAAiBW,YAAY,CAACI,QAAQ;AAG5C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { baModelFieldKeys, baModelKey } from "@/better-auth/plugin/constants";
|
|
2
|
+
import { set } from "../../utils/set";
|
|
3
|
+
import { getSchemaCollectionSlug, getSchemaFieldName } from "../build-collections/utils/collection-schema";
|
|
4
|
+
export function configureOrganizationPlugin(plugin, resolvedSchemas) {
|
|
5
|
+
const models = [
|
|
6
|
+
baModelKey.organization,
|
|
7
|
+
baModelKey.member,
|
|
8
|
+
baModelKey.invitation,
|
|
9
|
+
baModelKey.team,
|
|
10
|
+
baModelKey.session,
|
|
11
|
+
baModelKey.teamMember
|
|
12
|
+
];
|
|
13
|
+
models.forEach((model)=>set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model)));
|
|
14
|
+
set(plugin, `schema.${baModelKey.member}.fields.organizationId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.member, baModelFieldKeys.member.organizationId));
|
|
15
|
+
set(plugin, `schema.${baModelKey.member}.fields.organizationId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.organization));
|
|
16
|
+
set(plugin, `schema.${baModelKey.member}.fields.userId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.member, baModelFieldKeys.member.userId));
|
|
17
|
+
set(plugin, `schema.${baModelKey.member}.fields.userId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.user));
|
|
18
|
+
set(plugin, `schema.${baModelKey.invitation}.fields.organizationId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.invitation, baModelFieldKeys.invitation.organizationId));
|
|
19
|
+
set(plugin, `schema.${baModelKey.invitation}.fields.organizationId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.organization));
|
|
20
|
+
set(plugin, `schema.${baModelKey.invitation}.fields.inviterId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.invitation, baModelFieldKeys.invitation.inviterId));
|
|
21
|
+
set(plugin, `schema.${baModelKey.invitation}.fields.inviterId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.user));
|
|
22
|
+
set(plugin, `schema.${baModelKey.invitation}.fields.teamId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.invitation, baModelFieldKeys.invitation.teamId));
|
|
23
|
+
set(plugin, `schema.${baModelKey.invitation}.fields.teamId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.team));
|
|
24
|
+
set(plugin, `schema.${baModelKey.team}.fields.organizationId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.team, baModelFieldKeys.team.organizationId));
|
|
25
|
+
set(plugin, `schema.${baModelKey.team}.fields.organizationId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.user));
|
|
26
|
+
set(plugin, `schema.${baModelKey.teamMember}.fields.teamId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.teamMember, baModelFieldKeys.teamMember.teamId));
|
|
27
|
+
set(plugin, `schema.${baModelKey.teamMember}.fields.teamId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.team));
|
|
28
|
+
set(plugin, `schema.${baModelKey.teamMember}.fields.userId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.teamMember, baModelFieldKeys.teamMember.userId));
|
|
29
|
+
set(plugin, `schema.${baModelKey.teamMember}.fields.userId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.user));
|
|
30
|
+
set(plugin, `schema.${baModelKey.session}.fields.activeOrganizationId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.session, baModelFieldKeys.session.activeOrganizationId));
|
|
31
|
+
set(plugin, `schema.${baModelKey.session}.fields.activeTeamId.fieldName`, getSchemaFieldName(resolvedSchemas, baModelKey.session, baModelFieldKeys.session.activeTeamId));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=organizations-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.ts"],"sourcesContent":["import { baModelFieldKeys, baModelKey } from '@/better-auth/plugin/constants';\nimport type { BetterAuthSchemas } from '@/better-auth/types';\nimport { set } from '../../utils/set';\nimport {\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from '../build-collections/utils/collection-schema';\n\nexport function configureOrganizationPlugin(plugin: any, resolvedSchemas: BetterAuthSchemas): void {\n const models = [\n baModelKey.organization,\n baModelKey.member,\n baModelKey.invitation,\n baModelKey.team,\n baModelKey.session,\n baModelKey.teamMember,\n ] as const;\n models.forEach(model =>\n set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model))\n );\n\n set(\n plugin,\n `schema.${baModelKey.member}.fields.organizationId.fieldName`,\n getSchemaFieldName(resolvedSchemas, baModelKey.member, baModelFieldKeys.member.organizationId)\n );\n set(\n plugin,\n `schema.${baModelKey.member}.fields.organizationId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.organization)\n );\n set(\n plugin,\n `schema.${baModelKey.member}.fields.userId.fieldName`,\n getSchemaFieldName(resolvedSchemas, baModelKey.member, baModelFieldKeys.member.userId)\n );\n set(\n plugin,\n `schema.${baModelKey.member}.fields.userId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.user)\n );\n set(\n plugin,\n `schema.${baModelKey.invitation}.fields.organizationId.fieldName`,\n getSchemaFieldName(\n resolvedSchemas,\n baModelKey.invitation,\n baModelFieldKeys.invitation.organizationId\n )\n );\n set(\n plugin,\n `schema.${baModelKey.invitation}.fields.organizationId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.organization)\n );\n set(\n plugin,\n `schema.${baModelKey.invitation}.fields.inviterId.fieldName`,\n getSchemaFieldName(\n resolvedSchemas,\n baModelKey.invitation,\n baModelFieldKeys.invitation.inviterId\n )\n );\n set(\n plugin,\n `schema.${baModelKey.invitation}.fields.inviterId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.user)\n );\n set(\n plugin,\n `schema.${baModelKey.invitation}.fields.teamId.fieldName`,\n getSchemaFieldName(resolvedSchemas, baModelKey.invitation, baModelFieldKeys.invitation.teamId)\n );\n set(\n plugin,\n `schema.${baModelKey.invitation}.fields.teamId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.team)\n );\n set(\n plugin,\n `schema.${baModelKey.team}.fields.organizationId.fieldName`,\n getSchemaFieldName(resolvedSchemas, baModelKey.team, baModelFieldKeys.team.organizationId)\n );\n set(\n plugin,\n `schema.${baModelKey.team}.fields.organizationId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.user)\n );\n set(\n plugin,\n `schema.${baModelKey.teamMember}.fields.teamId.fieldName`,\n getSchemaFieldName(resolvedSchemas, baModelKey.teamMember, baModelFieldKeys.teamMember.teamId)\n );\n set(\n plugin,\n `schema.${baModelKey.teamMember}.fields.teamId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.team)\n );\n set(\n plugin,\n `schema.${baModelKey.teamMember}.fields.userId.fieldName`,\n getSchemaFieldName(resolvedSchemas, baModelKey.teamMember, baModelFieldKeys.teamMember.userId)\n );\n set(\n plugin,\n `schema.${baModelKey.teamMember}.fields.userId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.user)\n );\n set(\n plugin,\n `schema.${baModelKey.session}.fields.activeOrganizationId.fieldName`,\n getSchemaFieldName(\n resolvedSchemas,\n baModelKey.session,\n baModelFieldKeys.session.activeOrganizationId\n )\n );\n set(\n plugin,\n `schema.${baModelKey.session}.fields.activeTeamId.fieldName`,\n getSchemaFieldName(resolvedSchemas, baModelKey.session, baModelFieldKeys.session.activeTeamId)\n );\n}\n"],"names":["baModelFieldKeys","baModelKey","set","getSchemaCollectionSlug","getSchemaFieldName","configureOrganizationPlugin","plugin","resolvedSchemas","models","organization","member","invitation","team","session","teamMember","forEach","model","organizationId","userId","user","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,QACA,CAAC,OAAO,EAAEL,WAAWa,UAAU,CAAC,+BAA+B,CAAC,EAChEX,wBAAwBI,iBAAiBN,WAAWkB,IAAI;IAE1DjB,IACEI,QACA,CAAC,OAAO,EAAEL,WAAWY,OAAO,CAAC,sCAAsC,CAAC,EACpET,mBACEG,iBACAN,WAAWY,OAAO,EAClBb,iBAAiBa,OAAO,CAACS,oBAAoB;IAGjDpB,IACEI,QACA,CAAC,OAAO,EAAEL,WAAWY,OAAO,CAAC,8BAA8B,CAAC,EAC5DT,mBAAmBG,iBAAiBN,WAAWY,OAAO,EAAEb,iBAAiBa,OAAO,CAACU,YAAY;AAEjG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { baModelFieldKeys, baModelKey } from "@/better-auth/plugin/constants";
|
|
2
|
+
import { set } from "../../utils/set";
|
|
3
|
+
import { getSchemaCollectionSlug, getSchemaFieldName } from "../build-collections/utils/collection-schema";
|
|
4
|
+
export function configurePasskeyPlugin(plugin, resolvedSchemas) {
|
|
5
|
+
const model = baModelKey.passkey;
|
|
6
|
+
set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model));
|
|
7
|
+
set(plugin, `schema.${model}.fields.userId.fieldName`, getSchemaFieldName(resolvedSchemas, model, baModelFieldKeys.passkey.userId));
|
|
8
|
+
set(plugin, `schema.${model}.fields.userId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.user));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=passkey-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.ts"],"sourcesContent":["import { baModelFieldKeys, baModelKey } from '@/better-auth/plugin/constants';\nimport type { BetterAuthSchemas } from '@/better-auth/types';\nimport { set } from '../../utils/set';\nimport {\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from '../build-collections/utils/collection-schema';\n\nexport function configurePasskeyPlugin(plugin: any, resolvedSchemas: BetterAuthSchemas): void {\n const model = baModelKey.passkey;\n set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model));\n set(\n plugin,\n `schema.${model}.fields.userId.fieldName`,\n getSchemaFieldName(resolvedSchemas, model, baModelFieldKeys.passkey.userId)\n );\n set(\n plugin,\n `schema.${model}.fields.userId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.user)\n );\n}\n"],"names":["baModelFieldKeys","baModelKey","set","getSchemaCollectionSlug","getSchemaFieldName","configurePasskeyPlugin","plugin","resolvedSchemas","model","passkey","userId","user"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,iCAAiC;AAE9E,SAASC,GAAG,QAAQ,kBAAkB;AACtC,SACEC,uBAAuB,EACvBC,kBAAkB,QACb,+CAA+C;AAEtD,OAAO,SAASC,uBAAuBC,MAAW,EAAEC,eAAkC;IACpF,MAAMC,QAAQP,WAAWQ,OAAO;IAChCP,IAAII,QAAQ,CAAC,OAAO,EAAEE,MAAM,UAAU,CAAC,EAAEL,wBAAwBI,iBAAiBC;IAClFN,IACEI,QACA,CAAC,OAAO,EAAEE,MAAM,wBAAwB,CAAC,EACzCJ,mBAAmBG,iBAAiBC,OAAOR,iBAAiBS,OAAO,CAACC,MAAM;IAE5ER,IACEI,QACA,CAAC,OAAO,EAAEE,MAAM,+BAA+B,CAAC,EAChDL,wBAAwBI,iBAAiBN,WAAWU,IAAI;AAE5D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { baModelFieldKeys, baModelKey } from "@/better-auth/plugin/constants";
|
|
2
|
+
import { set } from "@/better-auth/plugin/utils/set";
|
|
3
|
+
import { getSchemaCollectionSlug, getSchemaFieldName } from "../build-collections/utils/collection-schema";
|
|
4
|
+
export function configureSsoPlugin(plugin, resolvedSchemas) {
|
|
5
|
+
const model = baModelKey.ssoProvider;
|
|
6
|
+
set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model));
|
|
7
|
+
set(plugin, `schema.${model}.fields.userId.fieldName`, getSchemaFieldName(resolvedSchemas, model, baModelFieldKeys.ssoProvider.userId));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=sso-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.ts"],"sourcesContent":["import { baModelFieldKeys, baModelKey } from '@/better-auth/plugin/constants';\nimport { set } from '@/better-auth/plugin/utils/set';\nimport type { BetterAuthSchemas } from '@/better-auth/types';\nimport {\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from '../build-collections/utils/collection-schema';\n\nexport function configureSsoPlugin(plugin: any, resolvedSchemas: BetterAuthSchemas): void {\n const model = baModelKey.ssoProvider;\n set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model));\n set(\n plugin,\n `schema.${model}.fields.userId.fieldName`,\n getSchemaFieldName(resolvedSchemas, model, baModelFieldKeys.ssoProvider.userId)\n );\n}\n"],"names":["baModelFieldKeys","baModelKey","set","getSchemaCollectionSlug","getSchemaFieldName","configureSsoPlugin","plugin","resolvedSchemas","model","ssoProvider","userId"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,iCAAiC;AAC9E,SAASC,GAAG,QAAQ,iCAAiC;AAErD,SACEC,uBAAuB,EACvBC,kBAAkB,QACb,+CAA+C;AAEtD,OAAO,SAASC,mBAAmBC,MAAW,EAAEC,eAAkC;IAChF,MAAMC,QAAQP,WAAWQ,WAAW;IACpCP,IAAII,QAAQ,CAAC,OAAO,EAAEE,MAAM,UAAU,CAAC,EAAEL,wBAAwBI,iBAAiBC;IAClFN,IACEI,QACA,CAAC,OAAO,EAAEE,MAAM,wBAAwB,CAAC,EACzCJ,mBAAmBG,iBAAiBC,OAAOR,iBAAiBS,WAAW,CAACC,MAAM;AAElF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { baModelFieldKeys, baModelKey } from "@/better-auth/plugin/constants";
|
|
2
|
+
import { set } from "@/better-auth/plugin/utils/set";
|
|
3
|
+
import { getSchemaCollectionSlug, getSchemaFieldName } from "../build-collections/utils/collection-schema";
|
|
4
|
+
export function configureTwoFactorPlugin(plugin, resolvedSchemas) {
|
|
5
|
+
const model = baModelKey.twoFactor;
|
|
6
|
+
set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model));
|
|
7
|
+
set(plugin, `schema.${model}.fields.userId.fieldName`, getSchemaFieldName(resolvedSchemas, model, baModelFieldKeys.twoFactor.userId));
|
|
8
|
+
set(plugin, `schema.${model}.fields.userId.references.model`, getSchemaCollectionSlug(resolvedSchemas, baModelKey.user));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=two-factor-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.ts"],"sourcesContent":["import { baModelFieldKeys, baModelKey } from '@/better-auth/plugin/constants';\nimport { set } from '@/better-auth/plugin/utils/set';\nimport type { BetterAuthSchemas } from '@/better-auth/types';\nimport {\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from '../build-collections/utils/collection-schema';\n\nexport function configureTwoFactorPlugin(plugin: any, resolvedSchemas: BetterAuthSchemas): void {\n const model = baModelKey.twoFactor;\n set(plugin, `schema.${model}.modelName`, getSchemaCollectionSlug(resolvedSchemas, model));\n set(\n plugin,\n `schema.${model}.fields.userId.fieldName`,\n getSchemaFieldName(resolvedSchemas, model, baModelFieldKeys.twoFactor.userId)\n );\n set(\n plugin,\n `schema.${model}.fields.userId.references.model`,\n getSchemaCollectionSlug(resolvedSchemas, baModelKey.user)\n );\n}\n"],"names":["baModelFieldKeys","baModelKey","set","getSchemaCollectionSlug","getSchemaFieldName","configureTwoFactorPlugin","plugin","resolvedSchemas","model","twoFactor","userId","user"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,iCAAiC;AAC9E,SAASC,GAAG,QAAQ,iCAAiC;AAErD,SACEC,uBAAuB,EACvBC,kBAAkB,QACb,+CAA+C;AAEtD,OAAO,SAASC,yBAAyBC,MAAW,EAAEC,eAAkC;IACtF,MAAMC,QAAQP,WAAWQ,SAAS;IAClCP,IAAII,QAAQ,CAAC,OAAO,EAAEE,MAAM,UAAU,CAAC,EAAEL,wBAAwBI,iBAAiBC;IAClFN,IACEI,QACA,CAAC,OAAO,EAAEE,MAAM,wBAAwB,CAAC,EACzCJ,mBAAmBG,iBAAiBC,OAAOR,iBAAiBS,SAAS,CAACC,MAAM;IAE9ER,IACEI,QACA,CAAC,OAAO,EAAEE,MAAM,+BAA+B,CAAC,EAChDL,wBAAwBI,iBAAiBN,WAAWU,IAAI;AAE5D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SanitizedBetterAuthOptions } from '@/better-auth/plugin/types';
|
|
2
|
+
/**
|
|
3
|
+
* Adds a before hook to the user create operation to ensure the password is set.
|
|
4
|
+
* This is necessary because the password is not set in the user create operation
|
|
5
|
+
* and is instead set in the sync password accounts hook.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ensurePasswordSetBeforeUserCreate(options: SanitizedBetterAuthOptions): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds a before hook to the user create operation to ensure the password is set.
|
|
3
|
+
* This is necessary because the password is not set in the user create operation
|
|
4
|
+
* and is instead set in the sync password accounts hook.
|
|
5
|
+
*/ export function ensurePasswordSetBeforeUserCreate(options) {
|
|
6
|
+
if (typeof options.databaseHooks !== 'object') options.databaseHooks = {};
|
|
7
|
+
if (typeof options.databaseHooks.user !== 'object') options.databaseHooks.user = {};
|
|
8
|
+
if (typeof options.databaseHooks.user.create !== 'object') options.databaseHooks.user.create = {};
|
|
9
|
+
const initialBeforeUserCreateHook = options.databaseHooks.user.create.before ?? null;
|
|
10
|
+
options.databaseHooks.user.create.before = async (user, ctx)=>{
|
|
11
|
+
if (!user.password) {
|
|
12
|
+
user.password = ctx?.body?.password ?? Array(3).fill(0).map(()=>Math.random().toString(36).slice(2)).join('');
|
|
13
|
+
}
|
|
14
|
+
if (typeof initialBeforeUserCreateHook === 'function') {
|
|
15
|
+
return initialBeforeUserCreateHook(user, ctx);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
data: user
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=ensure-password-set-before-create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.ts"],"sourcesContent":["import type { SanitizedBetterAuthOptions } from '@/better-auth/plugin/types';\n\n/**\n * Adds a before hook to the user create operation to ensure the password is set.\n * This is necessary because the password is not set in the user create operation\n * and is instead set in the sync password accounts hook.\n */\nexport function ensurePasswordSetBeforeUserCreate(options: SanitizedBetterAuthOptions) {\n if (typeof options.databaseHooks !== 'object') options.databaseHooks = {};\n if (typeof options.databaseHooks.user !== 'object') options.databaseHooks.user = {};\n if (typeof options.databaseHooks.user.create !== 'object') options.databaseHooks.user.create = {};\n const initialBeforeUserCreateHook = options.databaseHooks.user.create.before ?? null;\n\n options.databaseHooks.user.create.before = async (user, ctx) => {\n if (!(user as any).password) {\n (user as any).password =\n ctx?.body?.password ??\n Array(3)\n .fill(0)\n .map(() => Math.random().toString(36).slice(2))\n .join('');\n }\n if (typeof initialBeforeUserCreateHook === 'function') {\n return initialBeforeUserCreateHook(user, ctx);\n }\n return { data: user };\n };\n}\n"],"names":["ensurePasswordSetBeforeUserCreate","options","databaseHooks","user","create","initialBeforeUserCreateHook","before","ctx","password","body","Array","fill","map","Math","random","toString","slice","join","data"],"mappings":"AAEA;;;;CAIC,GACD,OAAO,SAASA,kCAAkCC,OAAmC;IACnF,IAAI,OAAOA,QAAQC,aAAa,KAAK,UAAUD,QAAQC,aAAa,GAAG,CAAC;IACxE,IAAI,OAAOD,QAAQC,aAAa,CAACC,IAAI,KAAK,UAAUF,QAAQC,aAAa,CAACC,IAAI,GAAG,CAAC;IAClF,IAAI,OAAOF,QAAQC,aAAa,CAACC,IAAI,CAACC,MAAM,KAAK,UAAUH,QAAQC,aAAa,CAACC,IAAI,CAACC,MAAM,GAAG,CAAC;IAChG,MAAMC,8BAA8BJ,QAAQC,aAAa,CAACC,IAAI,CAACC,MAAM,CAACE,MAAM,IAAI;IAEhFL,QAAQC,aAAa,CAACC,IAAI,CAACC,MAAM,CAACE,MAAM,GAAG,OAAOH,MAAMI;QACtD,IAAI,CAAC,AAACJ,KAAaK,QAAQ,EAAE;YAC1BL,KAAaK,QAAQ,GACpBD,KAAKE,MAAMD,YACXE,MAAM,GACHC,IAAI,CAAC,GACLC,GAAG,CAAC,IAAMC,KAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,KAAK,CAAC,IAC3CC,IAAI,CAAC;QACZ;QACA,IAAI,OAAOZ,gCAAgC,YAAY;YACrD,OAAOA,4BAA4BF,MAAMI;QAC3C;QACA,OAAO;YAAEW,MAAMf;QAAK;IACtB;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom implementation of password hashing that matches Payload's format
|
|
3
|
+
*
|
|
4
|
+
* Instead of using better-auth's scrypt, this uses pbkdf2 with the same
|
|
5
|
+
* parameters as Payload CMS
|
|
6
|
+
*
|
|
7
|
+
* @param password The password to hash
|
|
8
|
+
* @returns A string in the format {salt}:{hash}
|
|
9
|
+
*/
|
|
10
|
+
export declare const hashPassword: (password: string) => Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Verifies a password against a stored hash
|
|
13
|
+
*
|
|
14
|
+
* This function is flexible and can handle:
|
|
15
|
+
* 1. A combined string in format {salt}:{hash} (for account passwords)
|
|
16
|
+
* 2. When salt and hash need to be combined from user records
|
|
17
|
+
*
|
|
18
|
+
* @param params Object containing the hash and password
|
|
19
|
+
* @returns Boolean indicating if the password matches
|
|
20
|
+
*/
|
|
21
|
+
export declare const verifyPassword: ({ hash, password, salt, }: {
|
|
22
|
+
hash: string;
|
|
23
|
+
password: string;
|
|
24
|
+
salt?: string;
|
|
25
|
+
}) => Promise<boolean>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Mimics Payload's internal password hashing using pbkdf2
|
|
4
|
+
*
|
|
5
|
+
* This generates a hash compatible with Payload's internal auth system
|
|
6
|
+
* so that passwords set via better-auth can be used with Payload admin panel
|
|
7
|
+
*/ function pbkdf2Promisified(password, salt) {
|
|
8
|
+
return new Promise((resolve, reject)=>crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (err, hashRaw)=>err ? reject(err) : resolve(hashRaw)));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Generates random bytes for the salt
|
|
12
|
+
*/ function randomBytes() {
|
|
13
|
+
return new Promise((resolve, reject)=>crypto.randomBytes(32, (err, saltBuffer)=>err ? reject(err) : resolve(saltBuffer)));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Custom implementation of password hashing that matches Payload's format
|
|
17
|
+
*
|
|
18
|
+
* Instead of using better-auth's scrypt, this uses pbkdf2 with the same
|
|
19
|
+
* parameters as Payload CMS
|
|
20
|
+
*
|
|
21
|
+
* @param password The password to hash
|
|
22
|
+
* @returns A string in the format {salt}:{hash}
|
|
23
|
+
*/ export const hashPassword = async (password)=>{
|
|
24
|
+
const saltBuffer = await randomBytes();
|
|
25
|
+
const salt = saltBuffer.toString('hex');
|
|
26
|
+
const hashRaw = await pbkdf2Promisified(password, salt);
|
|
27
|
+
const hash = hashRaw.toString('hex');
|
|
28
|
+
return `${salt}:${hash}`;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Verifies a password against a stored hash
|
|
32
|
+
*
|
|
33
|
+
* This function is flexible and can handle:
|
|
34
|
+
* 1. A combined string in format {salt}:{hash} (for account passwords)
|
|
35
|
+
* 2. When salt and hash need to be combined from user records
|
|
36
|
+
*
|
|
37
|
+
* @param params Object containing the hash and password
|
|
38
|
+
* @returns Boolean indicating if the password matches
|
|
39
|
+
*/ export const verifyPassword = async ({ hash, password, salt })=>{
|
|
40
|
+
let saltValue;
|
|
41
|
+
let storedHash;
|
|
42
|
+
// If salt is provided separately (from user record), use it with the hash
|
|
43
|
+
if (salt) {
|
|
44
|
+
saltValue = salt;
|
|
45
|
+
storedHash = hash;
|
|
46
|
+
} else {
|
|
47
|
+
// Otherwise, split the combined format (from account.password)
|
|
48
|
+
const parts = hash.split(':');
|
|
49
|
+
if (parts.length !== 2) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
[saltValue, storedHash] = parts;
|
|
53
|
+
}
|
|
54
|
+
if (!saltValue || !storedHash) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const hashRaw = await pbkdf2Promisified(password, saltValue);
|
|
58
|
+
const computedHash = hashRaw.toString('hex');
|
|
59
|
+
return storedHash === computedHash;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=password.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.ts"],"sourcesContent":["import crypto from 'crypto';\n\n/**\n * Mimics Payload's internal password hashing using pbkdf2\n *\n * This generates a hash compatible with Payload's internal auth system\n * so that passwords set via better-auth can be used with Payload admin panel\n */\nfunction pbkdf2Promisified(password: string, salt: string): Promise<Buffer> {\n return new Promise((resolve, reject) =>\n crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (err, hashRaw) =>\n err ? reject(err) : resolve(hashRaw)\n )\n );\n}\n\n/**\n * Generates random bytes for the salt\n */\nfunction randomBytes(): Promise<Buffer> {\n return new Promise((resolve, reject) =>\n crypto.randomBytes(32, (err, saltBuffer) => (err ? reject(err) : resolve(saltBuffer)))\n );\n}\n\n/**\n * Custom implementation of password hashing that matches Payload's format\n *\n * Instead of using better-auth's scrypt, this uses pbkdf2 with the same\n * parameters as Payload CMS\n *\n * @param password The password to hash\n * @returns A string in the format {salt}:{hash}\n */\nexport const hashPassword = async (password: string): Promise<string> => {\n const saltBuffer = await randomBytes();\n const salt = saltBuffer.toString('hex');\n\n const hashRaw = await pbkdf2Promisified(password, salt);\n const hash = hashRaw.toString('hex');\n\n return `${salt}:${hash}`;\n};\n\n/**\n * Verifies a password against a stored hash\n *\n * This function is flexible and can handle:\n * 1. A combined string in format {salt}:{hash} (for account passwords)\n * 2. When salt and hash need to be combined from user records\n *\n * @param params Object containing the hash and password\n * @returns Boolean indicating if the password matches\n */\nexport const verifyPassword = async ({\n hash,\n password,\n salt,\n}: {\n hash: string;\n password: string;\n salt?: string;\n}): Promise<boolean> => {\n let saltValue: string;\n let storedHash: string;\n\n // If salt is provided separately (from user record), use it with the hash\n if (salt) {\n saltValue = salt;\n storedHash = hash;\n } else {\n // Otherwise, split the combined format (from account.password)\n const parts = hash.split(':');\n if (parts.length !== 2) {\n return false;\n }\n [saltValue, storedHash] = parts as [string, string];\n }\n\n if (!saltValue || !storedHash) {\n return false;\n }\n\n const hashRaw = await pbkdf2Promisified(password, saltValue);\n const computedHash = hashRaw.toString('hex');\n\n return storedHash === computedHash;\n};\n"],"names":["crypto","pbkdf2Promisified","password","salt","Promise","resolve","reject","pbkdf2","err","hashRaw","randomBytes","saltBuffer","hashPassword","toString","hash","verifyPassword","saltValue","storedHash","parts","split","length","computedHash"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAE5B;;;;;CAKC,GACD,SAASC,kBAAkBC,QAAgB,EAAEC,IAAY;IACvD,OAAO,IAAIC,QAAQ,CAACC,SAASC,SAC3BN,OAAOO,MAAM,CAACL,UAAUC,MAAM,OAAO,KAAK,UAAU,CAACK,KAAKC,UACxDD,MAAMF,OAAOE,OAAOH,QAAQI;AAGlC;AAEA;;CAEC,GACD,SAASC;IACP,OAAO,IAAIN,QAAQ,CAACC,SAASC,SAC3BN,OAAOU,WAAW,CAAC,IAAI,CAACF,KAAKG,aAAgBH,MAAMF,OAAOE,OAAOH,QAAQM;AAE7E;AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMC,eAAe,OAAOV;IACjC,MAAMS,aAAa,MAAMD;IACzB,MAAMP,OAAOQ,WAAWE,QAAQ,CAAC;IAEjC,MAAMJ,UAAU,MAAMR,kBAAkBC,UAAUC;IAClD,MAAMW,OAAOL,QAAQI,QAAQ,CAAC;IAE9B,OAAO,GAAGV,KAAK,CAAC,EAAEW,MAAM;AAC1B,EAAE;AAEF;;;;;;;;;CASC,GACD,OAAO,MAAMC,iBAAiB,OAAO,EACnCD,IAAI,EACJZ,QAAQ,EACRC,IAAI,EAKL;IACC,IAAIa;IACJ,IAAIC;IAEJ,0EAA0E;IAC1E,IAAId,MAAM;QACRa,YAAYb;QACZc,aAAaH;IACf,OAAO;QACL,+DAA+D;QAC/D,MAAMI,QAAQJ,KAAKK,KAAK,CAAC;QACzB,IAAID,MAAME,MAAM,KAAK,GAAG;YACtB,OAAO;QACT;QACA,CAACJ,WAAWC,WAAW,GAAGC;IAC5B;IAEA,IAAI,CAACF,aAAa,CAACC,YAAY;QAC7B,OAAO;IACT;IAEA,MAAMR,UAAU,MAAMR,kBAAkBC,UAAUc;IAClD,MAAMK,eAAeZ,QAAQI,QAAQ,CAAC;IAEtC,OAAOI,eAAeI;AACxB,EAAE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SanitizedBetterAuthOptions } from '@/better-auth/plugin/types';
|
|
2
|
+
import type { BetterAuthPluginOptions } from '@/better-auth/types';
|
|
3
|
+
/**
|
|
4
|
+
* Mofies options object and adds a middleware to check for admin invite for sign up
|
|
5
|
+
*/
|
|
6
|
+
export declare const requireAdminInviteForSignUpMiddleware: ({ options, pluginOptions, }: {
|
|
7
|
+
options: SanitizedBetterAuthOptions;
|
|
8
|
+
pluginOptions: BetterAuthPluginOptions;
|
|
9
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { baseSlugs } from "@/better-auth/plugin/constants";
|
|
2
|
+
import { APIError, createAuthMiddleware } from "better-auth/api";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
const throwUnauthorizedError = ()=>{
|
|
5
|
+
throw new APIError('UNAUTHORIZED', {
|
|
6
|
+
message: 'signup disabled'
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Mofies options object and adds a middleware to check for admin invite for sign up
|
|
11
|
+
*/ export const requireAdminInviteForSignUpMiddleware = async ({ options, pluginOptions })=>{
|
|
12
|
+
options.hooks = options.hooks ?? {};
|
|
13
|
+
const originalBefore = options.hooks.before;
|
|
14
|
+
options.hooks.before = createAuthMiddleware(async (ctx)=>{
|
|
15
|
+
if (ctx.path !== '/sign-up/email' && // not an email sign-up request
|
|
16
|
+
!(ctx.path === '/sign-in/social' && ctx.body?.requestSignUp // not a social sign-in request with sign-up intent
|
|
17
|
+
)) return ctx;
|
|
18
|
+
// Using any because BetterAuth ctx.body structure varies by request type and cannot be strictly typed
|
|
19
|
+
const adminInviteToken = // biome-ignore lint/suspicious/noExplicitAny: BetterAuth ctx.body structure varies by request type
|
|
20
|
+
ctx?.query?.adminInviteToken ?? ctx.body.adminInviteToken;
|
|
21
|
+
if (!!pluginOptions.requireAdminInviteForSignUp && !z.string().uuid().safeParse(adminInviteToken).success) {
|
|
22
|
+
throwUnauthorizedError();
|
|
23
|
+
return ctx;
|
|
24
|
+
}
|
|
25
|
+
const query = {
|
|
26
|
+
field: 'token',
|
|
27
|
+
value: adminInviteToken,
|
|
28
|
+
operator: 'eq'
|
|
29
|
+
};
|
|
30
|
+
const isValidAdminInvitation = await ctx.context.adapter.count({
|
|
31
|
+
model: pluginOptions.adminInvitations?.slug ?? baseSlugs.adminInvitations,
|
|
32
|
+
where: [
|
|
33
|
+
query
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
if (isValidAdminInvitation) {
|
|
37
|
+
// Using any because BetterAuth middleware functions have dynamic signatures that vary by context
|
|
38
|
+
// biome-ignore lint/suspicious/noExplicitAny: BetterAuth middleware functions have dynamic signatures
|
|
39
|
+
if (originalBefore) return originalBefore(ctx);
|
|
40
|
+
return ctx;
|
|
41
|
+
}
|
|
42
|
+
throwUnauthorizedError();
|
|
43
|
+
return ctx;
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=require-admin-invite-for-sign-up-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.ts"],"sourcesContent":["import { baseSlugs } from '@/better-auth/plugin/constants';\nimport type { SanitizedBetterAuthOptions } from '@/better-auth/plugin/types';\nimport type { BetterAuthPluginOptions } from '@/better-auth/types';\nimport type { Where } from 'better-auth';\nimport { APIError, createAuthMiddleware } from 'better-auth/api';\nimport { z } from 'zod';\n\nconst throwUnauthorizedError = () => {\n throw new APIError('UNAUTHORIZED', {\n message: 'signup disabled', // mimic: https://github.com/better-auth/better-auth/blob/171fab5273cf38f46cf207b0d99c8ccdda64c2fb/packages/better-auth/src/oauth2/link-account.ts#L108\n });\n};\n\n/**\n * Mofies options object and adds a middleware to check for admin invite for sign up\n */\nexport const requireAdminInviteForSignUpMiddleware = async ({\n options,\n pluginOptions,\n}: {\n options: SanitizedBetterAuthOptions;\n pluginOptions: BetterAuthPluginOptions;\n}) => {\n options.hooks = options.hooks ?? {};\n const originalBefore = options.hooks.before;\n options.hooks.before = createAuthMiddleware(async ctx => {\n if (\n ctx.path !== '/sign-up/email' && // not an email sign-up request\n !(ctx.path === '/sign-in/social' && ctx.body?.requestSignUp) // not a social sign-in request with sign-up intent\n )\n return ctx;\n // Using any because BetterAuth ctx.body structure varies by request type and cannot be strictly typed\n const adminInviteToken =\n // biome-ignore lint/suspicious/noExplicitAny: BetterAuth ctx.body structure varies by request type\n ctx?.query?.adminInviteToken ?? (ctx.body as any).adminInviteToken;\n if (\n !!pluginOptions.requireAdminInviteForSignUp &&\n !z.string().uuid().safeParse(adminInviteToken).success\n ) {\n throwUnauthorizedError();\n return ctx;\n }\n const query: Where = {\n field: 'token',\n value: adminInviteToken,\n operator: 'eq',\n };\n const isValidAdminInvitation = await ctx.context.adapter.count({\n model: pluginOptions.adminInvitations?.slug ?? baseSlugs.adminInvitations,\n where: [query],\n });\n if (isValidAdminInvitation) {\n // Using any because BetterAuth middleware functions have dynamic signatures that vary by context\n // biome-ignore lint/suspicious/noExplicitAny: BetterAuth middleware functions have dynamic signatures\n if (originalBefore) return (originalBefore as any)(ctx as any);\n return ctx;\n }\n throwUnauthorizedError();\n return ctx;\n });\n};\n"],"names":["baseSlugs","APIError","createAuthMiddleware","z","throwUnauthorizedError","message","requireAdminInviteForSignUpMiddleware","options","pluginOptions","hooks","originalBefore","before","ctx","path","body","requestSignUp","adminInviteToken","query","requireAdminInviteForSignUp","string","uuid","safeParse","success","field","value","operator","isValidAdminInvitation","context","adapter","count","model","adminInvitations","slug","where"],"mappings":"AAAA,SAASA,SAAS,QAAQ,iCAAiC;AAI3D,SAASC,QAAQ,EAAEC,oBAAoB,QAAQ,kBAAkB;AACjE,SAASC,CAAC,QAAQ,MAAM;AAExB,MAAMC,yBAAyB;IAC7B,MAAM,IAAIH,SAAS,gBAAgB;QACjCI,SAAS;IACX;AACF;AAEA;;CAEC,GACD,OAAO,MAAMC,wCAAwC,OAAO,EAC1DC,OAAO,EACPC,aAAa,EAId;IACCD,QAAQE,KAAK,GAAGF,QAAQE,KAAK,IAAI,CAAC;IAClC,MAAMC,iBAAiBH,QAAQE,KAAK,CAACE,MAAM;IAC3CJ,QAAQE,KAAK,CAACE,MAAM,GAAGT,qBAAqB,OAAMU;QAChD,IACEA,IAAIC,IAAI,KAAK,oBAAoB,+BAA+B;QAChE,CAAED,CAAAA,IAAIC,IAAI,KAAK,qBAAqBD,IAAIE,IAAI,EAAEC,cAAe,mDAAmD;QAAtD,GAE1D,OAAOH;QACT,sGAAsG;QACtG,MAAMI,mBACJ,mGAAmG;QACnGJ,KAAKK,OAAOD,oBAAoB,AAACJ,IAAIE,IAAI,CAASE,gBAAgB;QACpE,IACE,CAAC,CAACR,cAAcU,2BAA2B,IAC3C,CAACf,EAAEgB,MAAM,GAAGC,IAAI,GAAGC,SAAS,CAACL,kBAAkBM,OAAO,EACtD;YACAlB;YACA,OAAOQ;QACT;QACA,MAAMK,QAAe;YACnBM,OAAO;YACPC,OAAOR;YACPS,UAAU;QACZ;QACA,MAAMC,yBAAyB,MAAMd,IAAIe,OAAO,CAACC,OAAO,CAACC,KAAK,CAAC;YAC7DC,OAAOtB,cAAcuB,gBAAgB,EAAEC,QAAQhC,UAAU+B,gBAAgB;YACzEE,OAAO;gBAAChB;aAAM;QAChB;QACA,IAAIS,wBAAwB;YAC1B,iGAAiG;YACjG,sGAAsG;YACtG,IAAIhB,gBAAgB,OAAO,AAACA,eAAuBE;YACnD,OAAOA;QACT;QACAR;QACA,OAAOQ;IACT;AACF,EAAE"}
|
package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BetterAuthSchemas, SanitizedBetterAuthOptions } from '@/better-auth/plugin/types';
|
|
2
|
+
import type { Config, Payload } from 'payload';
|
|
3
|
+
/**
|
|
4
|
+
* Sets up a middleware that enforces the saveToJwt configuration when setting session data.
|
|
5
|
+
* This ensures that only fields specified in saveToJwt are included in the cookie cache
|
|
6
|
+
* for both user and session objects.
|
|
7
|
+
*
|
|
8
|
+
* The middleware runs after authentication and filters the session data based on
|
|
9
|
+
* the collection configurations before storing it in the cookie cache.
|
|
10
|
+
*/
|
|
11
|
+
export declare function saveToJwtMiddleware({ sanitizedOptions, config, resolvedSchemas, }: {
|
|
12
|
+
sanitizedOptions: SanitizedBetterAuthOptions;
|
|
13
|
+
config: Payload['config'] | Config | Promise<Payload['config'] | Config>;
|
|
14
|
+
resolvedSchemas: BetterAuthSchemas;
|
|
15
|
+
}): void;
|