@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,226 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { adminRoutes } from "@/better-auth/plugin/constants";
|
|
4
|
+
import { AdminSocialProviderButtons } from "@/better-auth/plugin/payload/components/social-provider-buttons";
|
|
5
|
+
import { getSafeRedirect } from "@/better-auth/plugin/payload/utils/get-safe-redirect";
|
|
6
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
7
|
+
import { FormProvider, useForm } from "react-hook-form";
|
|
8
|
+
const valueOrDefaultString = (value, defaultValue)=>value ?? defaultValue;
|
|
9
|
+
import { Button, Link, toast, useConfig, useTranslation } from "@payloadcms/ui";
|
|
10
|
+
import { createAuthClient } from "better-auth/client";
|
|
11
|
+
import { passkeyClient, twoFactorClient, usernameClient } from "better-auth/client/plugins";
|
|
12
|
+
import { useRouter } from "next/navigation";
|
|
13
|
+
import { formatAdminURL, getLoginOptions } from "payload/shared";
|
|
14
|
+
import React, { useMemo, useState } from "react";
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
const baseClass = 'login__form';
|
|
17
|
+
const LoginForm = ({ hasUsernamePlugin, hasPasskeyPlugin, prefillEmail, prefillPassword, prefillUsername, searchParams, loginWithUsername, baseURL, basePath })=>{
|
|
18
|
+
const { config } = useConfig();
|
|
19
|
+
const router = useRouter();
|
|
20
|
+
const adminRoute1 = valueOrDefaultString(config?.routes?.admin, '/admin');
|
|
21
|
+
const { t } = useTranslation();
|
|
22
|
+
const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername);
|
|
23
|
+
const searchParamError = searchParams?.error;
|
|
24
|
+
const redirectUrl = getSafeRedirect(searchParams?.redirect ?? '', adminRoute1);
|
|
25
|
+
const forgotPasswordUrl = formatAdminURL({
|
|
26
|
+
adminRoute: adminRoute1,
|
|
27
|
+
path: adminRoutes?.forgotPassword
|
|
28
|
+
});
|
|
29
|
+
const authClient = useMemo(()=>{
|
|
30
|
+
const options = {
|
|
31
|
+
plugins: [
|
|
32
|
+
usernameClient(),
|
|
33
|
+
twoFactorClient({
|
|
34
|
+
onTwoFactorRedirect () {
|
|
35
|
+
router.push(`${adminRoute1}${adminRoutes.twoFactorVerify}?redirect=${redirectUrl}`);
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
...hasPasskeyPlugin ? [
|
|
39
|
+
passkeyClient()
|
|
40
|
+
] : []
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
if (baseURL) options.baseURL = baseURL;
|
|
44
|
+
if (basePath) options.basePath = basePath;
|
|
45
|
+
return createAuthClient(options);
|
|
46
|
+
}, []);
|
|
47
|
+
const loginType = useMemo(()=>{
|
|
48
|
+
if (canLoginWithEmail && canLoginWithUsername && hasUsernamePlugin) return 'emailOrUsername';
|
|
49
|
+
if (canLoginWithUsername && hasUsernamePlugin) return 'username';
|
|
50
|
+
return 'email';
|
|
51
|
+
}, [
|
|
52
|
+
canLoginWithEmail,
|
|
53
|
+
canLoginWithUsername,
|
|
54
|
+
hasUsernamePlugin
|
|
55
|
+
]);
|
|
56
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
57
|
+
const isValidEmail = (email)=>emailRegex.test(email);
|
|
58
|
+
const loginSchema = z.object({
|
|
59
|
+
login: z.string().min(1, t('validation:required') || 'Required'),
|
|
60
|
+
password: z.string().min(1, t('validation:required') || 'Required')
|
|
61
|
+
});
|
|
62
|
+
const methods = useForm({
|
|
63
|
+
defaultValues: {
|
|
64
|
+
login: prefillEmail ?? prefillUsername ?? '',
|
|
65
|
+
password: prefillPassword ?? ''
|
|
66
|
+
},
|
|
67
|
+
resolver: zodResolver(loginSchema),
|
|
68
|
+
mode: 'onSubmit'
|
|
69
|
+
});
|
|
70
|
+
const [requireEmailVerification, setRequireEmailVerification] = useState(false);
|
|
71
|
+
const onSubmit = async (value)=>{
|
|
72
|
+
const { login, password } = value;
|
|
73
|
+
const isEmail = isValidEmail(login);
|
|
74
|
+
try {
|
|
75
|
+
const { data, error } = await (loginType === 'email' || loginType === 'emailOrUsername' && isEmail ? authClient.signIn.email({
|
|
76
|
+
email: login,
|
|
77
|
+
password,
|
|
78
|
+
callbackURL: redirectUrl
|
|
79
|
+
}) : authClient.signIn.username({
|
|
80
|
+
username: login,
|
|
81
|
+
password
|
|
82
|
+
}));
|
|
83
|
+
if (error) {
|
|
84
|
+
if (error.code === 'EMAIL_NOT_VERIFIED') {
|
|
85
|
+
setRequireEmailVerification(true);
|
|
86
|
+
}
|
|
87
|
+
if (error.message) {
|
|
88
|
+
toast.error(error.message.charAt(0).toUpperCase() + error.message.slice(1));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (data?.token) {
|
|
92
|
+
toast.success(t('general:success'));
|
|
93
|
+
window.location.href = redirectUrl;
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
toast.error(t('error:unknown') ?? 'An unexpected error occurred');
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
if (requireEmailVerification) {
|
|
100
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
101
|
+
className: "form-header",
|
|
102
|
+
style: {
|
|
103
|
+
textAlign: 'center'
|
|
104
|
+
},
|
|
105
|
+
children: [
|
|
106
|
+
/*#__PURE__*/ _jsx("h1", {
|
|
107
|
+
children: "Please verify your email"
|
|
108
|
+
}),
|
|
109
|
+
t('authentication:emailSent') && /*#__PURE__*/ _jsx("p", {
|
|
110
|
+
children: t('authentication:emailSent')
|
|
111
|
+
})
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const getLoginTypeLabel = ()=>{
|
|
116
|
+
const labels = {
|
|
117
|
+
email: t('general:email') ?? 'Email',
|
|
118
|
+
username: t('authentication:username') ?? 'Username',
|
|
119
|
+
emailOrUsername: t('authentication:emailOrUsername') ?? 'Email or Username'
|
|
120
|
+
};
|
|
121
|
+
return labels[loginType];
|
|
122
|
+
};
|
|
123
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
124
|
+
className: `${baseClass}__wrapper`,
|
|
125
|
+
children: [
|
|
126
|
+
searchParamError && searchParamError === 'signup_disabled' && /*#__PURE__*/ _jsx("div", {
|
|
127
|
+
style: {
|
|
128
|
+
color: 'red',
|
|
129
|
+
marginBottom: '1rem'
|
|
130
|
+
},
|
|
131
|
+
children: "Sign up is disabled."
|
|
132
|
+
}),
|
|
133
|
+
/*#__PURE__*/ _jsx(FormProvider, {
|
|
134
|
+
...methods,
|
|
135
|
+
children: /*#__PURE__*/ _jsxs("form", {
|
|
136
|
+
className: baseClass,
|
|
137
|
+
onSubmit: methods.handleSubmit(onSubmit),
|
|
138
|
+
children: [
|
|
139
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
140
|
+
className: baseClass,
|
|
141
|
+
children: [
|
|
142
|
+
/*#__PURE__*/ _jsx("input", {
|
|
143
|
+
type: "text",
|
|
144
|
+
value: methods.watch('login'),
|
|
145
|
+
onChange: (e)=>methods.setValue('login', e.target.value),
|
|
146
|
+
autoComplete: hasPasskeyPlugin ? 'username webauthn' : 'email',
|
|
147
|
+
placeholder: getLoginTypeLabel(),
|
|
148
|
+
style: {
|
|
149
|
+
width: '100%',
|
|
150
|
+
padding: '0.5rem',
|
|
151
|
+
marginBottom: '1rem'
|
|
152
|
+
}
|
|
153
|
+
}),
|
|
154
|
+
/*#__PURE__*/ _jsx("input", {
|
|
155
|
+
type: "password",
|
|
156
|
+
value: methods.watch('password'),
|
|
157
|
+
onChange: (e)=>methods.setValue('password', e.target.value),
|
|
158
|
+
autoComplete: hasPasskeyPlugin ? 'current-password webauthn' : 'current-password',
|
|
159
|
+
placeholder: t('general:password'),
|
|
160
|
+
style: {
|
|
161
|
+
width: '100%',
|
|
162
|
+
padding: '0.5rem',
|
|
163
|
+
marginBottom: '1rem'
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
]
|
|
167
|
+
}),
|
|
168
|
+
/*#__PURE__*/ _jsx(Link, {
|
|
169
|
+
href: forgotPasswordUrl,
|
|
170
|
+
prefetch: false,
|
|
171
|
+
children: t('authentication:forgotPasswordQuestion')
|
|
172
|
+
}),
|
|
173
|
+
/*#__PURE__*/ _jsx("button", {
|
|
174
|
+
type: "submit",
|
|
175
|
+
style: {
|
|
176
|
+
display: 'none'
|
|
177
|
+
},
|
|
178
|
+
tabIndex: -1
|
|
179
|
+
}),
|
|
180
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
181
|
+
type: "submit",
|
|
182
|
+
children: t('authentication:login')
|
|
183
|
+
})
|
|
184
|
+
]
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
export const AdminLoginClient = ({ loginMethods, hasUsernamePlugin, hasPasskeyPlugin, prefillEmail, prefillPassword, prefillUsername, searchParams, loginWithUsername, baseURL, basePath })=>{
|
|
191
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
192
|
+
children: [
|
|
193
|
+
loginMethods.includes('emailPassword') && (()=>{
|
|
194
|
+
const props = {
|
|
195
|
+
hasUsernamePlugin,
|
|
196
|
+
hasPasskeyPlugin,
|
|
197
|
+
searchParams,
|
|
198
|
+
loginWithUsername
|
|
199
|
+
};
|
|
200
|
+
if (prefillEmail) props.prefillEmail = prefillEmail;
|
|
201
|
+
if (prefillPassword) props.prefillPassword = prefillPassword;
|
|
202
|
+
if (prefillUsername) props.prefillUsername = prefillUsername;
|
|
203
|
+
if (baseURL) props.baseURL = baseURL;
|
|
204
|
+
if (basePath) props.basePath = basePath;
|
|
205
|
+
return /*#__PURE__*/ _jsx(LoginForm, {
|
|
206
|
+
...props
|
|
207
|
+
});
|
|
208
|
+
})(),
|
|
209
|
+
(()=>{
|
|
210
|
+
const props = {
|
|
211
|
+
isSignup: false,
|
|
212
|
+
loginMethods,
|
|
213
|
+
setLoading: ()=>{},
|
|
214
|
+
redirectUrl: getSafeRedirect(searchParams?.redirect ?? '', adminRoute)
|
|
215
|
+
};
|
|
216
|
+
if (baseURL) props.baseURL = baseURL;
|
|
217
|
+
if (basePath) props.basePath = basePath;
|
|
218
|
+
return /*#__PURE__*/ _jsx(AdminSocialProviderButtons, {
|
|
219
|
+
...props
|
|
220
|
+
});
|
|
221
|
+
})()
|
|
222
|
+
]
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/better-auth/plugin/payload/views/admin-login/client.tsx"],"sourcesContent":["'use client';\n\nimport { adminRoutes } from '@/better-auth/plugin/constants';\nimport { AdminSocialProviderButtons } from '@/better-auth/plugin/payload/components/social-provider-buttons';\nimport { getSafeRedirect } from '@/better-auth/plugin/payload/utils/get-safe-redirect';\nimport type { LoginMethod } from '@/better-auth/plugin/types';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { FormProvider, useForm } from 'react-hook-form';\nconst valueOrDefaultString = (value: string | undefined, defaultValue: string): string =>\n value ?? defaultValue;\nimport { Button, Link, toast, useConfig, useTranslation } from '@payloadcms/ui';\nimport { createAuthClient } from 'better-auth/client';\nimport { passkeyClient, twoFactorClient, usernameClient } from 'better-auth/client/plugins';\nimport { useRouter } from 'next/navigation';\nimport type { LoginWithUsernameOptions } from 'payload';\nimport { formatAdminURL, getLoginOptions } from 'payload/shared';\nimport React, { useMemo, useState } from 'react';\nimport { z } from 'zod';\n\ntype AdminLoginClientProps = {\n loginMethods: LoginMethod[];\n hasUsernamePlugin: boolean;\n hasPasskeyPlugin: boolean;\n prefillEmail?: string;\n prefillPassword?: string;\n prefillUsername?: string;\n searchParams: { [key: string]: string | string[] | undefined };\n loginWithUsername: false | LoginWithUsernameOptions;\n baseURL?: string;\n basePath?: string;\n};\n\nconst baseClass = 'login__form';\n\nconst LoginForm: React.FC<{\n hasUsernamePlugin: boolean;\n hasPasskeyPlugin: boolean;\n prefillEmail?: string;\n prefillPassword?: string;\n prefillUsername?: string;\n searchParams: { [key: string]: string | string[] | undefined };\n loginWithUsername: false | LoginWithUsernameOptions;\n baseURL?: string;\n basePath?: string;\n}> = ({\n hasUsernamePlugin,\n hasPasskeyPlugin,\n prefillEmail,\n prefillPassword,\n prefillUsername,\n searchParams,\n loginWithUsername,\n baseURL,\n basePath,\n}) => {\n const { config } = useConfig();\n const router = useRouter();\n const adminRoute = valueOrDefaultString(config?.routes?.admin, '/admin');\n const { t } = useTranslation();\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername);\n const searchParamError = searchParams?.error;\n const redirectUrl = getSafeRedirect((searchParams?.redirect as string) ?? '', adminRoute);\n const forgotPasswordUrl = formatAdminURL({\n adminRoute,\n path: adminRoutes?.forgotPassword as `/${string}`,\n });\n const authClient = useMemo(() => {\n const options: any = {\n plugins: [\n usernameClient() as any,\n twoFactorClient({\n onTwoFactorRedirect() {\n router.push(`${adminRoute}${adminRoutes.twoFactorVerify}?redirect=${redirectUrl}`);\n },\n }) as any,\n ...(hasPasskeyPlugin ? [passkeyClient() as any] : []),\n ],\n };\n if (baseURL) options.baseURL = baseURL;\n if (basePath) options.basePath = basePath;\n return createAuthClient(options);\n }, []);\n const loginType = useMemo(() => {\n if (canLoginWithEmail && canLoginWithUsername && hasUsernamePlugin) return 'emailOrUsername';\n if (canLoginWithUsername && hasUsernamePlugin) return 'username';\n return 'email';\n }, [canLoginWithEmail, canLoginWithUsername, hasUsernamePlugin]);\n\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n const isValidEmail = (email: string) => emailRegex.test(email);\n const loginSchema = z.object({\n login: z.string().min(1, t('validation:required') || 'Required'),\n password: z.string().min(1, t('validation:required') || 'Required'),\n });\n\n const methods = useForm({\n defaultValues: {\n login: prefillEmail ?? prefillUsername ?? '',\n password: prefillPassword ?? '',\n },\n resolver: zodResolver(loginSchema),\n mode: 'onSubmit',\n });\n\n const [requireEmailVerification, setRequireEmailVerification] = useState<boolean>(false);\n\n const onSubmit = async (value: { login: string; password: string }) => {\n const { login, password } = value;\n const isEmail = isValidEmail(login);\n try {\n const { data, error } = await (loginType === 'email' ||\n (loginType === 'emailOrUsername' && isEmail)\n ? (authClient as any).signIn.email({ email: login, password, callbackURL: redirectUrl })\n : (authClient as any).signIn.username({ username: login, password }));\n if (error) {\n if (error.code === 'EMAIL_NOT_VERIFIED') {\n setRequireEmailVerification(true);\n }\n if (error.message) {\n toast.error(error.message.charAt(0).toUpperCase() + error.message.slice(1));\n }\n }\n if (data?.token) {\n toast.success(t('general:success'));\n window.location.href = redirectUrl;\n }\n } catch (err) {\n toast.error(t('error:unknown') ?? 'An unexpected error occurred');\n }\n };\n\n if (requireEmailVerification) {\n return (\n <div className='form-header' style={{ textAlign: 'center' }}>\n <h1>Please verify your email</h1>\n {t('authentication:emailSent') && <p>{t('authentication:emailSent')}</p>}\n </div>\n );\n }\n\n const getLoginTypeLabel = () => {\n const labels = {\n email: t('general:email') ?? 'Email',\n username: t('authentication:username') ?? 'Username',\n emailOrUsername: t('authentication:emailOrUsername') ?? 'Email or Username',\n };\n return labels[loginType];\n };\n\n return (\n <div className={`${baseClass}__wrapper`}>\n {searchParamError && searchParamError === 'signup_disabled' && (\n <div style={{ color: 'red', marginBottom: '1rem' }}>Sign up is disabled.</div>\n )}\n <FormProvider {...methods}>\n <form className={baseClass} onSubmit={methods.handleSubmit(onSubmit)}>\n <div className={baseClass}>\n <input\n type='text'\n value={methods.watch('login')}\n onChange={(e: any) => methods.setValue('login', e.target.value)}\n autoComplete={hasPasskeyPlugin ? 'username webauthn' : 'email'}\n placeholder={getLoginTypeLabel()}\n style={{ width: '100%', padding: '0.5rem', marginBottom: '1rem' }}\n />\n <input\n type='password'\n value={methods.watch('password')}\n onChange={(e: any) => methods.setValue('password', e.target.value)}\n autoComplete={hasPasskeyPlugin ? 'current-password webauthn' : 'current-password'}\n placeholder={t('general:password')}\n style={{ width: '100%', padding: '0.5rem', marginBottom: '1rem' }}\n />\n </div>\n <Link href={forgotPasswordUrl} prefetch={false}>\n {t('authentication:forgotPasswordQuestion')}\n </Link>\n <button type='submit' style={{ display: 'none' }} tabIndex={-1} />\n <Button type='submit'>{t('authentication:login')}</Button>\n </form>\n </FormProvider>\n </div>\n );\n};\n\nexport const AdminLoginClient: React.FC<AdminLoginClientProps> = ({\n loginMethods,\n hasUsernamePlugin,\n hasPasskeyPlugin,\n prefillEmail,\n prefillPassword,\n prefillUsername,\n searchParams,\n loginWithUsername,\n baseURL,\n basePath,\n}) => {\n return (\n <>\n {loginMethods.includes('emailPassword') &&\n (() => {\n const props: any = {\n hasUsernamePlugin,\n hasPasskeyPlugin,\n searchParams,\n loginWithUsername,\n };\n if (prefillEmail) props.prefillEmail = prefillEmail;\n if (prefillPassword) props.prefillPassword = prefillPassword;\n if (prefillUsername) props.prefillUsername = prefillUsername;\n if (baseURL) props.baseURL = baseURL;\n if (basePath) props.basePath = basePath;\n return <LoginForm {...props} />;\n })()}\n {(() => {\n const props: any = {\n isSignup: false,\n loginMethods,\n setLoading: () => {},\n redirectUrl: getSafeRedirect((searchParams?.redirect as string) ?? '', adminRoute),\n };\n if (baseURL) props.baseURL = baseURL;\n if (basePath) props.basePath = basePath;\n return <AdminSocialProviderButtons {...props} />;\n })()}\n </>\n );\n};\n"],"names":["adminRoutes","AdminSocialProviderButtons","getSafeRedirect","zodResolver","FormProvider","useForm","valueOrDefaultString","value","defaultValue","Button","Link","toast","useConfig","useTranslation","createAuthClient","passkeyClient","twoFactorClient","usernameClient","useRouter","formatAdminURL","getLoginOptions","React","useMemo","useState","z","baseClass","LoginForm","hasUsernamePlugin","hasPasskeyPlugin","prefillEmail","prefillPassword","prefillUsername","searchParams","loginWithUsername","baseURL","basePath","config","router","adminRoute","routes","admin","t","canLoginWithEmail","canLoginWithUsername","searchParamError","error","redirectUrl","redirect","forgotPasswordUrl","path","forgotPassword","authClient","options","plugins","onTwoFactorRedirect","push","twoFactorVerify","loginType","emailRegex","isValidEmail","email","test","loginSchema","object","login","string","min","password","methods","defaultValues","resolver","mode","requireEmailVerification","setRequireEmailVerification","onSubmit","isEmail","data","signIn","callbackURL","username","code","message","charAt","toUpperCase","slice","token","success","window","location","href","err","div","className","style","textAlign","h1","p","getLoginTypeLabel","labels","emailOrUsername","color","marginBottom","form","handleSubmit","input","type","watch","onChange","e","setValue","target","autoComplete","placeholder","width","padding","prefetch","button","display","tabIndex","AdminLoginClient","loginMethods","includes","props","isSignup","setLoading"],"mappings":"AAAA;;AAEA,SAASA,WAAW,QAAQ,iCAAiC;AAC7D,SAASC,0BAA0B,QAAQ,kEAAkE;AAC7G,SAASC,eAAe,QAAQ,uDAAuD;AAEvF,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,YAAY,EAAEC,OAAO,QAAQ,kBAAkB;AACxD,MAAMC,uBAAuB,CAACC,OAA2BC,eACvDD,SAASC;AACX,SAASC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAEC,cAAc,QAAQ,iBAAiB;AAChF,SAASC,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,aAAa,EAAEC,eAAe,EAAEC,cAAc,QAAQ,6BAA6B;AAC5F,SAASC,SAAS,QAAQ,kBAAkB;AAE5C,SAASC,cAAc,EAAEC,eAAe,QAAQ,iBAAiB;AACjE,OAAOC,SAASC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACjD,SAASC,CAAC,QAAQ,MAAM;AAexB,MAAMC,YAAY;AAElB,MAAMC,YAUD,CAAC,EACJC,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,EACZC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,iBAAiB,EACjBC,OAAO,EACPC,QAAQ,EACT;IACC,MAAM,EAAEC,MAAM,EAAE,GAAGxB;IACnB,MAAMyB,SAASnB;IACf,MAAMoB,cAAahC,qBAAqB8B,QAAQG,QAAQC,OAAO;IAC/D,MAAM,EAAEC,CAAC,EAAE,GAAG5B;IACd,MAAM,EAAE6B,iBAAiB,EAAEC,oBAAoB,EAAE,GAAGvB,gBAAgBa;IACpE,MAAMW,mBAAmBZ,cAAca;IACvC,MAAMC,cAAc5C,gBAAgB,AAAC8B,cAAce,YAAuB,IAAIT;IAC9E,MAAMU,oBAAoB7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AIC,iBAAiB4F,MAAM5F,eAAe,GAAGA;gBAC7C,IAAIC,iBAAiB2F,MAAM3F,eAAe,GAAGA;gBAC7C,IAAIG,SAASwF,MAAMxF,OAAO,GAAGA;gBAC7B,IAAIC,UAAUuF,MAAMvF,QAAQ,GAAGA;gBAC/B,qBAAO,KAACT;oBAAW,GAAGgG,KAAK;;YAC7B,CAAA;YACA,CAAA;gBACA,MAAMA,QAAa;oBACjBC,UAAU;oBACVH;oBACAI,YAAY,KAAO;oBACnB9E,aAAa5C,gBAAgB,AAAC8B,cAAce,YAAuB,IAAIT;gBACzE;gBACA,IAAIJ,SAASwF,MAAMxF,OAAO,GAAGA;gBAC7B,IAAIC,UAAUuF,MAAMvF,QAAQ,GAAGA;gBAC/B,qBAAO,KAAClC;oBAA4B,GAAGyH,KAAK;;YAC9C,CAAA;;;AAGN,EAAE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { BetterAuthPluginOptions } from '@/better-auth/plugin/types';
|
|
3
|
+
import { type AdminViewServerProps } from 'payload';
|
|
4
|
+
export declare const loginBaseClass = "login";
|
|
5
|
+
interface AdminLoginProps extends AdminViewServerProps {
|
|
6
|
+
adminInvitationsSlug: string;
|
|
7
|
+
pluginOptions: BetterAuthPluginOptions;
|
|
8
|
+
}
|
|
9
|
+
declare const AdminLogin: React.FC<AdminLoginProps>;
|
|
10
|
+
export default AdminLogin;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { redirect } from "next/navigation";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { AdminLoginClient } from "./client";
|
|
5
|
+
// Logo component placeholder - using minimal logo for auth package
|
|
6
|
+
const Logo = ({ i18n })=>/*#__PURE__*/ _jsx("div", {
|
|
7
|
+
style: {
|
|
8
|
+
textAlign: 'center',
|
|
9
|
+
marginBottom: '2rem'
|
|
10
|
+
},
|
|
11
|
+
children: /*#__PURE__*/ _jsx("h1", {
|
|
12
|
+
style: {
|
|
13
|
+
fontSize: '1.5rem',
|
|
14
|
+
fontWeight: 'bold'
|
|
15
|
+
},
|
|
16
|
+
children: i18n?.t('general:appName') || 'Admin'
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
import { adminRoutes, defaults, supportedBAPluginIds } from "@/better-auth/plugin/constants";
|
|
20
|
+
import { checkPluginExists } from "@/better-auth/plugin/helpers/check-plugin-exists";
|
|
21
|
+
import { getSafeRedirect } from "@/better-auth/plugin/payload/utils/get-safe-redirect";
|
|
22
|
+
import { MinimalTemplate } from "@payloadcms/next/templates";
|
|
23
|
+
import { RenderServerComponent } from "@payloadcms/ui/elements/RenderServerComponent";
|
|
24
|
+
export const loginBaseClass = 'login';
|
|
25
|
+
const AdminLogin = async ({ initPageResult, params, searchParams, pluginOptions, adminInvitationsSlug })=>{
|
|
26
|
+
const { locale, permissions, req } = initPageResult;
|
|
27
|
+
const { i18n, payload: { config, collections }, payload, user } = req;
|
|
28
|
+
const { admin: { components: { afterLogin, beforeLogin } = {}, user: userSlug }, routes: { admin: adminRoute } } = config;
|
|
29
|
+
const adminRole = pluginOptions.users?.defaultAdminRole ?? defaults.adminRole;
|
|
30
|
+
const redirectUrl = getSafeRedirect(searchParams?.redirect ?? '', adminRoute);
|
|
31
|
+
if (user) {
|
|
32
|
+
redirect(redirectUrl);
|
|
33
|
+
}
|
|
34
|
+
const adminCount = await req.payload.count({
|
|
35
|
+
collection: userSlug,
|
|
36
|
+
where: {
|
|
37
|
+
role: {
|
|
38
|
+
equals: adminRole
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (adminCount.totalDocs === 0) {
|
|
43
|
+
// Check if we already have an admin invitation
|
|
44
|
+
const existingInvitations = await req.payload.find({
|
|
45
|
+
collection: adminInvitationsSlug,
|
|
46
|
+
where: {
|
|
47
|
+
role: {
|
|
48
|
+
equals: adminRole
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
let token;
|
|
53
|
+
if (existingInvitations.totalDocs > 0) {
|
|
54
|
+
// Use existing token
|
|
55
|
+
token = existingInvitations.docs[0].token;
|
|
56
|
+
} else {
|
|
57
|
+
// Generate a new secure invite token
|
|
58
|
+
token = crypto.randomUUID();
|
|
59
|
+
await req.payload.create({
|
|
60
|
+
collection: adminInvitationsSlug,
|
|
61
|
+
data: {
|
|
62
|
+
role: adminRole,
|
|
63
|
+
token
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
redirect(`${adminRoute}${adminRoutes.adminSignup}?token=${token}`);
|
|
68
|
+
}
|
|
69
|
+
// Filter out the first component from afterLogin array or set to undefined if not more than 1
|
|
70
|
+
// This is because of the custom login redirect component, we don't want an infinite loop
|
|
71
|
+
const filteredAfterLogin = Array.isArray(afterLogin) && afterLogin.length > 1 ? afterLogin.slice(1) : undefined;
|
|
72
|
+
const prefillAutoLogin = typeof config.admin?.autoLogin === 'object' && config.admin?.autoLogin.prefillOnly;
|
|
73
|
+
const prefillUsername = prefillAutoLogin && typeof config.admin?.autoLogin === 'object' ? config.admin?.autoLogin.username : undefined;
|
|
74
|
+
const prefillEmail = prefillAutoLogin && typeof config.admin?.autoLogin === 'object' ? config.admin?.autoLogin.email : undefined;
|
|
75
|
+
const prefillPassword = prefillAutoLogin && typeof config.admin?.autoLogin === 'object' ? config.admin?.autoLogin.password : undefined;
|
|
76
|
+
const hasUsernamePlugin = checkPluginExists(pluginOptions.betterAuthOptions ?? {}, supportedBAPluginIds.username);
|
|
77
|
+
const hasPasskeyPlugin = checkPluginExists(pluginOptions.betterAuthOptions ?? {}, supportedBAPluginIds.passkey);
|
|
78
|
+
const loginMethods = pluginOptions.admin?.loginMethods ?? [];
|
|
79
|
+
const loginWithUsername = collections?.[userSlug]?.config.auth.loginWithUsername;
|
|
80
|
+
const canLoginWithUsername = (hasUsernamePlugin && loginWithUsername) ?? false;
|
|
81
|
+
return /*#__PURE__*/ _jsxs(MinimalTemplate, {
|
|
82
|
+
className: loginBaseClass,
|
|
83
|
+
children: [
|
|
84
|
+
/*#__PURE__*/ _jsx("div", {
|
|
85
|
+
className: `${loginBaseClass}__brand`,
|
|
86
|
+
children: /*#__PURE__*/ _jsx(Logo, {
|
|
87
|
+
i18n: i18n,
|
|
88
|
+
locale: locale,
|
|
89
|
+
params: params,
|
|
90
|
+
payload: payload,
|
|
91
|
+
permissions: permissions,
|
|
92
|
+
searchParams: searchParams,
|
|
93
|
+
user: user ?? undefined
|
|
94
|
+
})
|
|
95
|
+
}),
|
|
96
|
+
beforeLogin && RenderServerComponent({
|
|
97
|
+
Component: beforeLogin,
|
|
98
|
+
importMap: payload.importMap,
|
|
99
|
+
serverProps: {
|
|
100
|
+
i18n,
|
|
101
|
+
locale: locale ?? 'en',
|
|
102
|
+
params,
|
|
103
|
+
payload,
|
|
104
|
+
permissions,
|
|
105
|
+
searchParams,
|
|
106
|
+
...user ? {
|
|
107
|
+
user
|
|
108
|
+
} : {}
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
(()=>{
|
|
112
|
+
const props = {
|
|
113
|
+
loginWithUsername: canLoginWithUsername,
|
|
114
|
+
hasUsernamePlugin,
|
|
115
|
+
hasPasskeyPlugin,
|
|
116
|
+
loginMethods,
|
|
117
|
+
searchParams: searchParams ?? {}
|
|
118
|
+
};
|
|
119
|
+
if (prefillEmail) props.prefillEmail = prefillEmail;
|
|
120
|
+
if (prefillPassword) props.prefillPassword = prefillPassword;
|
|
121
|
+
if (prefillUsername) props.prefillUsername = prefillUsername;
|
|
122
|
+
const baseURL = pluginOptions.betterAuthOptions?.baseURL;
|
|
123
|
+
const basePath = pluginOptions.betterAuthOptions?.basePath;
|
|
124
|
+
if (baseURL) props.baseURL = baseURL;
|
|
125
|
+
if (basePath) props.basePath = basePath;
|
|
126
|
+
return /*#__PURE__*/ _jsx(AdminLoginClient, {
|
|
127
|
+
...props
|
|
128
|
+
});
|
|
129
|
+
})(),
|
|
130
|
+
filteredAfterLogin && RenderServerComponent({
|
|
131
|
+
Component: filteredAfterLogin,
|
|
132
|
+
importMap: payload.importMap,
|
|
133
|
+
serverProps: {
|
|
134
|
+
i18n,
|
|
135
|
+
locale: locale ?? 'en',
|
|
136
|
+
params,
|
|
137
|
+
payload,
|
|
138
|
+
permissions,
|
|
139
|
+
searchParams,
|
|
140
|
+
...user ? {
|
|
141
|
+
user
|
|
142
|
+
} : {}
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
]
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
export default AdminLogin;
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/better-auth/plugin/payload/views/admin-login/index.tsx"],"sourcesContent":["import { redirect } from 'next/navigation';\nimport React from 'react';\nimport { AdminLoginClient } from './client';\n// Logo component placeholder - using minimal logo for auth package\nconst Logo = ({ i18n }: { i18n?: any; [key: string]: any }) => (\n <div style={{ textAlign: 'center', marginBottom: '2rem' }}>\n <h1 style={{ fontSize: '1.5rem', fontWeight: 'bold' }}>\n {i18n?.t('general:appName') || 'Admin'}\n </h1>\n </div>\n);\nimport { adminRoutes, defaults, supportedBAPluginIds } from '@/better-auth/plugin/constants';\nimport { checkPluginExists } from '@/better-auth/plugin/helpers/check-plugin-exists';\nimport { getSafeRedirect } from '@/better-auth/plugin/payload/utils/get-safe-redirect';\nimport type { BetterAuthPluginOptions } from '@/better-auth/plugin/types';\nimport { MinimalTemplate } from '@payloadcms/next/templates';\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent';\nimport { type AdminViewServerProps, type ServerProps } from 'payload';\n\nexport const loginBaseClass = 'login';\n\ninterface AdminLoginProps extends AdminViewServerProps {\n adminInvitationsSlug: string;\n pluginOptions: BetterAuthPluginOptions;\n}\n\nconst AdminLogin: React.FC<AdminLoginProps> = async ({\n initPageResult,\n params,\n searchParams,\n pluginOptions,\n adminInvitationsSlug,\n}: AdminLoginProps) => {\n const { locale, permissions, req } = initPageResult;\n const {\n i18n,\n payload: { config, collections },\n payload,\n user,\n } = req;\n\n const {\n admin: {\n components: { afterLogin, beforeLogin } = {},\n user: userSlug,\n },\n routes: { admin: adminRoute },\n } = config;\n\n const adminRole = pluginOptions.users?.defaultAdminRole ?? defaults.adminRole;\n const redirectUrl = getSafeRedirect((searchParams?.redirect as string) ?? '', adminRoute);\n\n if (user) {\n redirect(redirectUrl);\n }\n\n const adminCount = await req.payload.count({\n collection: userSlug as any,\n where: {\n role: {\n equals: adminRole,\n },\n },\n });\n\n if (adminCount.totalDocs === 0) {\n // Check if we already have an admin invitation\n const existingInvitations = await req.payload.find({\n collection: adminInvitationsSlug as any,\n where: {\n role: {\n equals: adminRole,\n },\n },\n });\n\n let token: string | undefined;\n\n if (existingInvitations.totalDocs > 0) {\n // Use existing token\n token = existingInvitations.docs[0].token;\n } else {\n // Generate a new secure invite token\n token = crypto.randomUUID();\n await req.payload.create({\n collection: adminInvitationsSlug as any,\n data: {\n role: adminRole,\n token,\n },\n });\n }\n\n redirect(`${adminRoute}${adminRoutes.adminSignup}?token=${token}`);\n }\n\n // Filter out the first component from afterLogin array or set to undefined if not more than 1\n // This is because of the custom login redirect component, we don't want an infinite loop\n const filteredAfterLogin =\n Array.isArray(afterLogin) && afterLogin.length > 1 ? afterLogin.slice(1) : undefined;\n const prefillAutoLogin =\n typeof config.admin?.autoLogin === 'object' && config.admin?.autoLogin.prefillOnly;\n const prefillUsername =\n prefillAutoLogin && typeof config.admin?.autoLogin === 'object'\n ? config.admin?.autoLogin.username\n : undefined;\n const prefillEmail =\n prefillAutoLogin && typeof config.admin?.autoLogin === 'object'\n ? config.admin?.autoLogin.email\n : undefined;\n const prefillPassword =\n prefillAutoLogin && typeof config.admin?.autoLogin === 'object'\n ? config.admin?.autoLogin.password\n : undefined;\n const hasUsernamePlugin = checkPluginExists(\n pluginOptions.betterAuthOptions ?? {},\n supportedBAPluginIds.username\n );\n const hasPasskeyPlugin = checkPluginExists(\n pluginOptions.betterAuthOptions ?? {},\n supportedBAPluginIds.passkey\n );\n const loginMethods = pluginOptions.admin?.loginMethods ?? [];\n const loginWithUsername = (collections as any)?.[userSlug]?.config.auth.loginWithUsername;\n const canLoginWithUsername = (hasUsernamePlugin && loginWithUsername) ?? false;\n\n return (\n <MinimalTemplate className={loginBaseClass}>\n <div className={`${loginBaseClass}__brand`}>\n <Logo\n i18n={i18n}\n locale={locale}\n params={params}\n payload={payload}\n permissions={permissions}\n searchParams={searchParams}\n user={user ?? undefined}\n />\n </div>\n {beforeLogin &&\n RenderServerComponent({\n Component: beforeLogin,\n importMap: payload.importMap,\n serverProps: {\n i18n,\n locale: (locale ?? 'en') as any,\n params,\n payload,\n permissions,\n searchParams,\n ...(user ? { user } : {}),\n } as unknown as ServerProps,\n })}\n {(() => {\n const props: any = {\n loginWithUsername: canLoginWithUsername,\n hasUsernamePlugin,\n hasPasskeyPlugin,\n loginMethods,\n searchParams: searchParams ?? {},\n };\n if (prefillEmail) props.prefillEmail = prefillEmail;\n if (prefillPassword) props.prefillPassword = prefillPassword;\n if (prefillUsername) props.prefillUsername = prefillUsername;\n const baseURL = pluginOptions.betterAuthOptions?.baseURL;\n const basePath = pluginOptions.betterAuthOptions?.basePath;\n if (baseURL) props.baseURL = baseURL;\n if (basePath) props.basePath = basePath;\n return <AdminLoginClient {...props} />;\n })()}\n {filteredAfterLogin &&\n RenderServerComponent({\n Component: filteredAfterLogin,\n importMap: payload.importMap,\n serverProps: {\n i18n,\n locale: (locale ?? 'en') as any,\n params,\n payload,\n permissions,\n searchParams,\n ...(user ? { user } : {}),\n } as unknown as ServerProps,\n })}\n </MinimalTemplate>\n );\n};\n\nexport default AdminLogin;\n"],"names":["redirect","React","AdminLoginClient","Logo","i18n","div","style","textAlign","marginBottom","h1","fontSize","fontWeight","t","adminRoutes","defaults","supportedBAPluginIds","checkPluginExists","getSafeRedirect","MinimalTemplate","RenderServerComponent","loginBaseClass","AdminLogin","initPageResult","params","searchParams","pluginOptions","adminInvitationsSlug","locale","permissions","req","payload","config","collections","user","admin","components","afterLogin","beforeLogin","userSlug","routes","adminRoute","adminRole","users","defaultAdminRole","redirectUrl","adminCount","count","collection","where","role","equals","totalDocs","existingInvitations","find","token","docs","crypto","randomUUID","create","data","adminSignup","filteredAfterLogin","Array","isArray","length","slice","undefined","prefillAutoLogin","autoLogin","prefillOnly","prefillUsername","username","prefillEmail","email","prefillPassword","password","hasUsernamePlugin","betterAuthOptions","hasPasskeyPlugin","passkey","loginMethods","loginWithUsername","auth","canLoginWithUsername","className","Component","importMap","serverProps","props","baseURL","basePath"],"mappings":";AAAA,SAASA,QAAQ,QAAQ,kBAAkB;AAC3C,OAAOC,WAAW,QAAQ;AAC1B,SAASC,gBAAgB,QAAQ,WAAW;AAC5C,mEAAmE;AACnE,MAAMC,OAAO,CAAC,EAAEC,IAAI,EAAsC,iBACxD,KAACC;QAAIC,OAAO;YAAEC,WAAW;YAAUC,cAAc;QAAO;kBACtD,cAAA,KAACC;YAAGH,OAAO;gBAAEI,UAAU;gBAAUC,YAAY;YAAO;sBACjDP,MAAMQ,EAAE,sBAAsB;;;AAIrC,SAASC,WAAW,EAAEC,QAAQ,EAAEC,oBAAoB,QAAQ,iCAAiC;AAC7F,SAASC,iBAAiB,QAAQ,mDAAmD;AACrF,SAASC,eAAe,QAAQ,uDAAuD;AAEvF,SAASC,eAAe,QAAQ,6BAA6B;AAC7D,SAASC,qBAAqB,QAAQ,gDAAgD;AAGtF,OAAO,MAAMC,iBAAiB,QAAQ;AAOtC,MAAMC,aAAwC,OAAO,EACnDC,cAAc,EACdC,MAAM,EACNC,YAAY,EACZC,aAAa,EACbC,oBAAoB,EACJ;IAChB,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAEC,GAAG,EAAE,GAAGP;IACrC,MAAM,EACJlB,IAAI,EACJ0B,SAAS,EAAEC,MAA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gBACA,MAAMuD,QAAa;oBACjBP,mBAAmBE;oBACnBP;oBACAE;oBACAE;oBACAxD,cAAcA,gBAAgB,CAAC;gBACjC;gBACA,IAAIgD,cAAcgB,MAAMhB,YAAY,GAAGA;gBACvC,IAAIE,iBAAiBc,MAAMd,eAAe,GAAGA;gBAC7C,IAAIJ,iBAAiBkB,MAAMlB,eAAe,GAAGA;gBAC7C,MAAMmB,UAAUhE,cAAcoD,iBAAiB,EAAEY;gBACjD,MAAMC,WAAWjE,cAAcoD,iBAAiB,EAAEa;gBAClD,IAAID,SAASD,MAAMC,OAAO,GAAGA;gBAC7B,IAAIC,UAAUF,MAAME,QAAQ,GAAGA;gBAC/B,qBAAO,KAACxF;oBAAkB,GAAGsF,KAAK;;YACpC,CAAA;YACC3B,sBACC1C,sBAAsB;gBACpBkE,WAAWxB;gBACXyB,WAAWxD,QAAQwD,SAAS;gBAC5BC,aAAa;oBACXnF;oBACAuB,QAASA,UAAU;oBACnBJ;oBACAO;oBACAF;oBACAJ;oBACA,GAAIS,OAAO;wBAAEA;oBAAK,IAAI,CAAC,CAAC;gBAC1B;YACF;;;AAGR;AAEA,eAAeZ,WAAW"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LoginMethod } from '@/better-auth/plugin/types';
|
|
2
|
+
import type { LoginWithUsernameOptions } from 'payload';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
type AdminSignupClientProps = {
|
|
5
|
+
adminInviteToken: string;
|
|
6
|
+
userSlug: string;
|
|
7
|
+
loginMethods: LoginMethod[];
|
|
8
|
+
searchParams: {
|
|
9
|
+
[key: string]: string | string[] | undefined;
|
|
10
|
+
};
|
|
11
|
+
loginWithUsername: false | LoginWithUsernameOptions;
|
|
12
|
+
baseURL?: string;
|
|
13
|
+
basePath?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const AdminSignupClient: React.FC<AdminSignupClientProps>;
|
|
16
|
+
export {};
|