@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.
Files changed (413) hide show
  1. package/LICENSE +202 -0
  2. package/dist/better-auth/adapter/__tests__/transform.test.js +213 -0
  3. package/dist/better-auth/adapter/__tests__/transform.test.js.map +1 -0
  4. package/dist/better-auth/adapter/generate-schema/biome.d.js +2 -0
  5. package/dist/better-auth/adapter/generate-schema/biome.d.js.map +1 -0
  6. package/dist/better-auth/adapter/generate-schema/generate-schema-builder.d.ts +5 -0
  7. package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js +482 -0
  8. package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js.map +1 -0
  9. package/dist/better-auth/adapter/generate-schema/get-payload-schema.d.ts +1 -0
  10. package/dist/better-auth/adapter/generate-schema/get-payload-schema.js +42 -0
  11. package/dist/better-auth/adapter/generate-schema/get-payload-schema.js.map +1 -0
  12. package/dist/better-auth/adapter/generate-schema/index.d.ts +4 -0
  13. package/dist/better-auth/adapter/generate-schema/index.js +19 -0
  14. package/dist/better-auth/adapter/generate-schema/index.js.map +1 -0
  15. package/dist/better-auth/adapter/generate-schema/utils.d.ts +2 -0
  16. package/dist/better-auth/adapter/generate-schema/utils.js +20 -0
  17. package/dist/better-auth/adapter/generate-schema/utils.js.map +1 -0
  18. package/dist/better-auth/adapter/index.d.ts +15 -0
  19. package/dist/better-auth/adapter/index.js +731 -0
  20. package/dist/better-auth/adapter/index.js.map +1 -0
  21. package/dist/better-auth/adapter/tests/adapter.test.js +174 -0
  22. package/dist/better-auth/adapter/tests/adapter.test.js.map +1 -0
  23. package/dist/better-auth/adapter/tests/base-collections-tests.js +575 -0
  24. package/dist/better-auth/adapter/tests/base-collections-tests.js.map +1 -0
  25. package/dist/better-auth/adapter/tests/dev/index.js +117 -0
  26. package/dist/better-auth/adapter/tests/dev/index.js.map +1 -0
  27. package/dist/better-auth/adapter/tests/dev/migrate.js +26 -0
  28. package/dist/better-auth/adapter/tests/dev/migrate.js.map +1 -0
  29. package/dist/better-auth/adapter/tests/dev/migrations/20250423_232936_init.js +218 -0
  30. package/dist/better-auth/adapter/tests/dev/migrations/20250423_232936_init.js.map +1 -0
  31. package/dist/better-auth/adapter/tests/dev/schema.js +160 -0
  32. package/dist/better-auth/adapter/tests/dev/schema.js.map +1 -0
  33. package/dist/better-auth/adapter/tests/plugins-tests.js +2 -0
  34. package/dist/better-auth/adapter/tests/plugins-tests.js.map +1 -0
  35. package/dist/better-auth/adapter/transform/index.d.ts +27 -0
  36. package/dist/better-auth/adapter/transform/index.js +664 -0
  37. package/dist/better-auth/adapter/transform/index.js.map +1 -0
  38. package/dist/better-auth/adapter/types.d.ts +10 -0
  39. package/dist/better-auth/adapter/types.js +3 -0
  40. package/dist/better-auth/adapter/types.js.map +1 -0
  41. package/dist/better-auth/generated-types.d.ts +285 -0
  42. package/dist/better-auth/index.d.ts +3 -0
  43. package/dist/better-auth/index.js +5 -0
  44. package/dist/better-auth/index.js.map +1 -0
  45. package/dist/better-auth/plugin/__tests__/plugin.test.js +162 -0
  46. package/dist/better-auth/plugin/__tests__/plugin.test.js.map +1 -0
  47. package/dist/better-auth/plugin/constants.d.ts +220 -0
  48. package/dist/better-auth/plugin/constants.js +249 -0
  49. package/dist/better-auth/plugin/constants.js.map +1 -0
  50. package/dist/better-auth/plugin/helpers/check-plugin-exists.d.ts +12 -0
  51. package/dist/better-auth/plugin/helpers/check-plugin-exists.js +14 -0
  52. package/dist/better-auth/plugin/helpers/check-plugin-exists.js.map +1 -0
  53. package/dist/better-auth/plugin/helpers/generate-verify-email-url.d.ts +29 -0
  54. package/dist/better-auth/plugin/helpers/generate-verify-email-url.js +46 -0
  55. package/dist/better-auth/plugin/helpers/generate-verify-email-url.js.map +1 -0
  56. package/dist/better-auth/plugin/helpers/get-admin-access.d.ts +7 -0
  57. package/dist/better-auth/plugin/helpers/get-admin-access.js +22 -0
  58. package/dist/better-auth/plugin/helpers/get-admin-access.js.map +1 -0
  59. package/dist/better-auth/plugin/helpers/get-all-roles.d.ts +5 -0
  60. package/dist/better-auth/plugin/helpers/get-all-roles.js +20 -0
  61. package/dist/better-auth/plugin/helpers/get-all-roles.js.map +1 -0
  62. package/dist/better-auth/plugin/helpers/get-better-auth-schema.d.ts +18 -0
  63. package/dist/better-auth/plugin/helpers/get-better-auth-schema.js +70 -0
  64. package/dist/better-auth/plugin/helpers/get-better-auth-schema.js.map +1 -0
  65. package/dist/better-auth/plugin/helpers/get-collection-slug.d.ts +5 -0
  66. package/dist/better-auth/plugin/helpers/get-collection-slug.js +20 -0
  67. package/dist/better-auth/plugin/helpers/get-collection-slug.js.map +1 -0
  68. package/dist/better-auth/plugin/helpers/get-collection.d.ts +15 -0
  69. package/dist/better-auth/plugin/helpers/get-collection.js +29 -0
  70. package/dist/better-auth/plugin/helpers/get-collection.js.map +1 -0
  71. package/dist/better-auth/plugin/helpers/get-ip.d.ts +2 -0
  72. package/dist/better-auth/plugin/helpers/get-ip.js +31 -0
  73. package/dist/better-auth/plugin/helpers/get-ip.js.map +1 -0
  74. package/dist/better-auth/plugin/helpers/get-signed-cookie.d.ts +2 -0
  75. package/dist/better-auth/plugin/helpers/get-signed-cookie.js +65 -0
  76. package/dist/better-auth/plugin/helpers/get-signed-cookie.js.map +1 -0
  77. package/dist/better-auth/plugin/helpers/index.d.ts +1 -0
  78. package/dist/better-auth/plugin/helpers/index.js +3 -0
  79. package/dist/better-auth/plugin/helpers/index.js.map +1 -0
  80. package/dist/better-auth/plugin/helpers/prepare-session-data.d.ts +59 -0
  81. package/dist/better-auth/plugin/helpers/prepare-session-data.js +49 -0
  82. package/dist/better-auth/plugin/helpers/prepare-session-data.js.map +1 -0
  83. package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.d.ts +20 -0
  84. package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.js +67 -0
  85. package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.js.map +1 -0
  86. package/dist/better-auth/plugin/index.d.ts +11 -0
  87. package/dist/better-auth/plugin/index.js +125 -0
  88. package/dist/better-auth/plugin/index.js.map +1 -0
  89. package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.d.ts +12 -0
  90. package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.js +87 -0
  91. package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.js.map +1 -0
  92. package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.d.ts +3 -0
  93. package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.js +60 -0
  94. package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.js.map +1 -0
  95. package/dist/better-auth/plugin/lib/build-collections/accounts/index.d.ts +3 -0
  96. package/dist/better-auth/plugin/lib/build-collections/accounts/index.js +154 -0
  97. package/dist/better-auth/plugin/lib/build-collections/accounts/index.js.map +1 -0
  98. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.d.ts +5 -0
  99. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.js +11 -0
  100. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.js.map +1 -0
  101. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.d.ts +2 -0
  102. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.js +8 -0
  103. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.js.map +1 -0
  104. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.d.ts +6 -0
  105. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.js +119 -0
  106. package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.js.map +1 -0
  107. package/dist/better-auth/plugin/lib/build-collections/api-keys.d.ts +3 -0
  108. package/dist/better-auth/plugin/lib/build-collections/api-keys.js +177 -0
  109. package/dist/better-auth/plugin/lib/build-collections/api-keys.js.map +1 -0
  110. package/dist/better-auth/plugin/lib/build-collections/device-code.d.ts +3 -0
  111. package/dist/better-auth/plugin/lib/build-collections/device-code.js +50 -0
  112. package/dist/better-auth/plugin/lib/build-collections/device-code.js.map +1 -0
  113. package/dist/better-auth/plugin/lib/build-collections/index.d.ts +10 -0
  114. package/dist/better-auth/plugin/lib/build-collections/index.js +73 -0
  115. package/dist/better-auth/plugin/lib/build-collections/index.js.map +1 -0
  116. package/dist/better-auth/plugin/lib/build-collections/invitations.d.ts +3 -0
  117. package/dist/better-auth/plugin/lib/build-collections/invitations.js +94 -0
  118. package/dist/better-auth/plugin/lib/build-collections/invitations.js.map +1 -0
  119. package/dist/better-auth/plugin/lib/build-collections/jwks.d.ts +3 -0
  120. package/dist/better-auth/plugin/lib/build-collections/jwks.js +59 -0
  121. package/dist/better-auth/plugin/lib/build-collections/jwks.js.map +1 -0
  122. package/dist/better-auth/plugin/lib/build-collections/members.d.ts +3 -0
  123. package/dist/better-auth/plugin/lib/build-collections/members.js +73 -0
  124. package/dist/better-auth/plugin/lib/build-collections/members.js.map +1 -0
  125. package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.d.ts +3 -0
  126. package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.js +107 -0
  127. package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.js.map +1 -0
  128. package/dist/better-auth/plugin/lib/build-collections/oauth-applications.d.ts +3 -0
  129. package/dist/better-auth/plugin/lib/build-collections/oauth-applications.js +118 -0
  130. package/dist/better-auth/plugin/lib/build-collections/oauth-applications.js.map +1 -0
  131. package/dist/better-auth/plugin/lib/build-collections/oauth-consents.d.ts +3 -0
  132. package/dist/better-auth/plugin/lib/build-collections/oauth-consents.js +89 -0
  133. package/dist/better-auth/plugin/lib/build-collections/oauth-consents.js.map +1 -0
  134. package/dist/better-auth/plugin/lib/build-collections/organizations.d.ts +3 -0
  135. package/dist/better-auth/plugin/lib/build-collections/organizations.js +70 -0
  136. package/dist/better-auth/plugin/lib/build-collections/organizations.js.map +1 -0
  137. package/dist/better-auth/plugin/lib/build-collections/passkeys.d.ts +3 -0
  138. package/dist/better-auth/plugin/lib/build-collections/passkeys.js +115 -0
  139. package/dist/better-auth/plugin/lib/build-collections/passkeys.js.map +1 -0
  140. package/dist/better-auth/plugin/lib/build-collections/sessions.d.ts +3 -0
  141. package/dist/better-auth/plugin/lib/build-collections/sessions.js +170 -0
  142. package/dist/better-auth/plugin/lib/build-collections/sessions.js.map +1 -0
  143. package/dist/better-auth/plugin/lib/build-collections/sso-providers.d.ts +3 -0
  144. package/dist/better-auth/plugin/lib/build-collections/sso-providers.js +81 -0
  145. package/dist/better-auth/plugin/lib/build-collections/sso-providers.js.map +1 -0
  146. package/dist/better-auth/plugin/lib/build-collections/subscriptions.d.ts +3 -0
  147. package/dist/better-auth/plugin/lib/build-collections/subscriptions.js +111 -0
  148. package/dist/better-auth/plugin/lib/build-collections/subscriptions.js.map +1 -0
  149. package/dist/better-auth/plugin/lib/build-collections/team-members.d.ts +3 -0
  150. package/dist/better-auth/plugin/lib/build-collections/team-members.js +57 -0
  151. package/dist/better-auth/plugin/lib/build-collections/team-members.js.map +1 -0
  152. package/dist/better-auth/plugin/lib/build-collections/teams.d.ts +3 -0
  153. package/dist/better-auth/plugin/lib/build-collections/teams.js +76 -0
  154. package/dist/better-auth/plugin/lib/build-collections/teams.js.map +1 -0
  155. package/dist/better-auth/plugin/lib/build-collections/two-factors.d.ts +3 -0
  156. package/dist/better-auth/plugin/lib/build-collections/two-factors.js +67 -0
  157. package/dist/better-auth/plugin/lib/build-collections/two-factors.js.map +1 -0
  158. package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.d.ts +7 -0
  159. package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.js +53 -0
  160. package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.js.map +1 -0
  161. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.d.ts +11 -0
  162. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.js +75 -0
  163. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.js.map +1 -0
  164. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.d.ts +4 -0
  165. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.js +6 -0
  166. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.js.map +1 -0
  167. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.d.ts +2 -0
  168. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.js +115 -0
  169. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.js.map +1 -0
  170. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.d.ts +3 -0
  171. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.js +64 -0
  172. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.js.map +1 -0
  173. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.d.ts +3 -0
  174. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.js +80 -0
  175. package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.js.map +1 -0
  176. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.d.ts +6 -0
  177. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.js +79 -0
  178. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.js.map +1 -0
  179. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.d.ts +2 -0
  180. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.js +82 -0
  181. package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.js.map +1 -0
  182. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.d.ts +2 -0
  183. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.js +54 -0
  184. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.js.map +1 -0
  185. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.d.ts +6 -0
  186. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.js +15 -0
  187. package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.js.map +1 -0
  188. package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.d.ts +6 -0
  189. package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.js +8 -0
  190. package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.js.map +1 -0
  191. package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.d.ts +2 -0
  192. package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.js +17 -0
  193. package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.js.map +1 -0
  194. package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.d.ts +2 -0
  195. package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.js +91 -0
  196. package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.js.map +1 -0
  197. package/dist/better-auth/plugin/lib/build-collections/users/index.d.ts +3 -0
  198. package/dist/better-auth/plugin/lib/build-collections/users/index.js +341 -0
  199. package/dist/better-auth/plugin/lib/build-collections/users/index.js.map +1 -0
  200. package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.d.ts +15 -0
  201. package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.js +24 -0
  202. package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.js.map +1 -0
  203. package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.d.ts +10 -0
  204. package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.js +67 -0
  205. package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.js.map +1 -0
  206. package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.d.ts +9 -0
  207. package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.js +94 -0
  208. package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.js.map +1 -0
  209. package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.d.ts +7 -0
  210. package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.js +35 -0
  211. package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.js.map +1 -0
  212. package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.d.ts +12 -0
  213. package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.js +25 -0
  214. package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.js.map +1 -0
  215. package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.d.ts +14 -0
  216. package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.js +67 -0
  217. package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.js.map +1 -0
  218. package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.d.ts +20 -0
  219. package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.js +98 -0
  220. package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.js.map +1 -0
  221. package/dist/better-auth/plugin/lib/build-collections/verifications.d.ts +3 -0
  222. package/dist/better-auth/plugin/lib/build-collections/verifications.js +87 -0
  223. package/dist/better-auth/plugin/lib/build-collections/verifications.js.map +1 -0
  224. package/dist/better-auth/plugin/lib/get-payload-auth.d.ts +5 -0
  225. package/dist/better-auth/plugin/lib/get-payload-auth.js +9 -0
  226. package/dist/better-auth/plugin/lib/get-payload-auth.js.map +1 -0
  227. package/dist/better-auth/plugin/lib/init-better-auth.d.ts +7 -0
  228. package/dist/better-auth/plugin/lib/init-better-auth.js +46 -0
  229. package/dist/better-auth/plugin/lib/init-better-auth.js.map +1 -0
  230. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.d.ts +2 -0
  231. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.js +9 -0
  232. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.js.map +1 -0
  233. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.d.ts +2 -0
  234. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.js +10 -0
  235. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.js.map +1 -0
  236. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.d.ts +2 -0
  237. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.js +8 -0
  238. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.js.map +1 -0
  239. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.d.ts +10 -0
  240. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.js +156 -0
  241. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.js.map +1 -0
  242. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.d.ts +2 -0
  243. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.js +18 -0
  244. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.js.map +1 -0
  245. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.d.ts +2 -0
  246. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.js +34 -0
  247. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.js.map +1 -0
  248. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.d.ts +2 -0
  249. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.js +11 -0
  250. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.js.map +1 -0
  251. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.d.ts +2 -0
  252. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.js +10 -0
  253. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.js.map +1 -0
  254. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.d.ts +2 -0
  255. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.js +11 -0
  256. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.js.map +1 -0
  257. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.d.ts +7 -0
  258. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.js +23 -0
  259. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.js.map +1 -0
  260. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.d.ts +25 -0
  261. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.js +62 -0
  262. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.js.map +1 -0
  263. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.d.ts +9 -0
  264. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.js +47 -0
  265. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.js.map +1 -0
  266. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.d.ts +15 -0
  267. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.js +42 -0
  268. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.js.map +1 -0
  269. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.d.ts +9 -0
  270. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.js +63 -0
  271. package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.js.map +1 -0
  272. package/dist/better-auth/plugin/lib/set-login-methods.d.ts +4 -0
  273. package/dist/better-auth/plugin/lib/set-login-methods.js +14 -0
  274. package/dist/better-auth/plugin/lib/set-login-methods.js.map +1 -0
  275. package/dist/better-auth/plugin/payload/components/admin-buttons/index.d.ts +9 -0
  276. package/dist/better-auth/plugin/payload/components/admin-buttons/index.js +143 -0
  277. package/dist/better-auth/plugin/payload/components/admin-buttons/index.js.map +1 -0
  278. package/dist/better-auth/plugin/payload/components/admin-invite-button/index.d.ts +10 -0
  279. package/dist/better-auth/plugin/payload/components/admin-invite-button/index.js +219 -0
  280. package/dist/better-auth/plugin/payload/components/admin-invite-button/index.js.map +1 -0
  281. package/dist/better-auth/plugin/payload/components/logout-button.d.ts +4 -0
  282. package/dist/better-auth/plugin/payload/components/logout-button.js +24 -0
  283. package/dist/better-auth/plugin/payload/components/logout-button.js.map +1 -0
  284. package/dist/better-auth/plugin/payload/components/passkeys/add-button.d.ts +8 -0
  285. package/dist/better-auth/plugin/payload/components/passkeys/add-button.js +117 -0
  286. package/dist/better-auth/plugin/payload/components/passkeys/add-button.js.map +1 -0
  287. package/dist/better-auth/plugin/payload/components/passkeys/client.d.ts +3 -0
  288. package/dist/better-auth/plugin/payload/components/passkeys/client.js +66 -0
  289. package/dist/better-auth/plugin/payload/components/passkeys/client.js.map +1 -0
  290. package/dist/better-auth/plugin/payload/components/passkeys/index.d.ts +4 -0
  291. package/dist/better-auth/plugin/payload/components/passkeys/index.js +52 -0
  292. package/dist/better-auth/plugin/payload/components/passkeys/index.js.map +1 -0
  293. package/dist/better-auth/plugin/payload/components/passkeys/list.d.ts +8 -0
  294. package/dist/better-auth/plugin/payload/components/passkeys/list.js +57 -0
  295. package/dist/better-auth/plugin/payload/components/passkeys/list.js.map +1 -0
  296. package/dist/better-auth/plugin/payload/components/passkeys/types.d.ts +22 -0
  297. package/dist/better-auth/plugin/payload/components/passkeys/types.js +3 -0
  298. package/dist/better-auth/plugin/payload/components/passkeys/types.js.map +1 -0
  299. package/dist/better-auth/plugin/payload/components/rsc-redirect.d.ts +6 -0
  300. package/dist/better-auth/plugin/payload/components/rsc-redirect.js +7 -0
  301. package/dist/better-auth/plugin/payload/components/rsc-redirect.js.map +1 -0
  302. package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.d.ts +15 -0
  303. package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.js +157 -0
  304. package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.js.map +1 -0
  305. package/dist/better-auth/plugin/payload/components/token-field.d.ts +4 -0
  306. package/dist/better-auth/plugin/payload/components/token-field.js +31 -0
  307. package/dist/better-auth/plugin/payload/components/token-field.js.map +1 -0
  308. package/dist/better-auth/plugin/payload/components/two-factor-auth/index.d.ts +8 -0
  309. package/dist/better-auth/plugin/payload/components/two-factor-auth/index.js +300 -0
  310. package/dist/better-auth/plugin/payload/components/two-factor-auth/index.js.map +1 -0
  311. package/dist/better-auth/plugin/payload/exports/client.d.ts +6 -0
  312. package/dist/better-auth/plugin/payload/exports/client.js +8 -0
  313. package/dist/better-auth/plugin/payload/exports/client.js.map +1 -0
  314. package/dist/better-auth/plugin/payload/exports/rsc.d.ts +8 -0
  315. package/dist/better-auth/plugin/payload/exports/rsc.js +10 -0
  316. package/dist/better-auth/plugin/payload/exports/rsc.js.map +1 -0
  317. package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.d.ts +2 -0
  318. package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.js +9 -0
  319. package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.js.map +1 -0
  320. package/dist/better-auth/plugin/payload/utils/get-safe-redirect.d.ts +1 -0
  321. package/dist/better-auth/plugin/payload/utils/get-safe-redirect.js +22 -0
  322. package/dist/better-auth/plugin/payload/utils/get-safe-redirect.js.map +1 -0
  323. package/dist/better-auth/plugin/payload/views/admin-login/client.d.ts +19 -0
  324. package/dist/better-auth/plugin/payload/views/admin-login/client.js +226 -0
  325. package/dist/better-auth/plugin/payload/views/admin-login/client.js.map +1 -0
  326. package/dist/better-auth/plugin/payload/views/admin-login/index.d.ts +10 -0
  327. package/dist/better-auth/plugin/payload/views/admin-login/index.js +150 -0
  328. package/dist/better-auth/plugin/payload/views/admin-login/index.js.map +1 -0
  329. package/dist/better-auth/plugin/payload/views/admin-signup/client.d.ts +16 -0
  330. package/dist/better-auth/plugin/payload/views/admin-signup/client.js +299 -0
  331. package/dist/better-auth/plugin/payload/views/admin-signup/client.js.map +1 -0
  332. package/dist/better-auth/plugin/payload/views/admin-signup/index.d.ts +9 -0
  333. package/dist/better-auth/plugin/payload/views/admin-signup/index.js +104 -0
  334. package/dist/better-auth/plugin/payload/views/admin-signup/index.js.map +1 -0
  335. package/dist/better-auth/plugin/payload/views/forgot-password/client.d.ts +7 -0
  336. package/dist/better-auth/plugin/payload/views/forgot-password/client.js +119 -0
  337. package/dist/better-auth/plugin/payload/views/forgot-password/client.js.map +1 -0
  338. package/dist/better-auth/plugin/payload/views/forgot-password/index.d.ts +8 -0
  339. package/dist/better-auth/plugin/payload/views/forgot-password/index.js +78 -0
  340. package/dist/better-auth/plugin/payload/views/forgot-password/index.js.map +1 -0
  341. package/dist/better-auth/plugin/payload/views/reset-password/client.d.ts +10 -0
  342. package/dist/better-auth/plugin/payload/views/reset-password/client.js +144 -0
  343. package/dist/better-auth/plugin/payload/views/reset-password/client.js.map +1 -0
  344. package/dist/better-auth/plugin/payload/views/reset-password/index.d.ts +8 -0
  345. package/dist/better-auth/plugin/payload/views/reset-password/index.js +96 -0
  346. package/dist/better-auth/plugin/payload/views/reset-password/index.js.map +1 -0
  347. package/dist/better-auth/plugin/payload/views/two-factor-verify/client.d.ts +6 -0
  348. package/dist/better-auth/plugin/payload/views/two-factor-verify/client.js +96 -0
  349. package/dist/better-auth/plugin/payload/views/two-factor-verify/client.js.map +1 -0
  350. package/dist/better-auth/plugin/payload/views/two-factor-verify/index.d.ts +9 -0
  351. package/dist/better-auth/plugin/payload/views/two-factor-verify/index.js +56 -0
  352. package/dist/better-auth/plugin/payload/views/two-factor-verify/index.js.map +1 -0
  353. package/dist/better-auth/plugin/types.d.ts +429 -0
  354. package/dist/better-auth/plugin/types.js +3 -0
  355. package/dist/better-auth/plugin/types.js.map +1 -0
  356. package/dist/better-auth/plugin/utils/set.d.ts +39 -0
  357. package/dist/better-auth/plugin/utils/set.js +103 -0
  358. package/dist/better-auth/plugin/utils/set.js.map +1 -0
  359. package/dist/better-auth/scripts/generate-types.d.ts +1 -0
  360. package/dist/better-auth/scripts/generate-types.js +234 -0
  361. package/dist/better-auth/scripts/generate-types.js.map +1 -0
  362. package/dist/better-auth/types.d.ts +2 -0
  363. package/dist/better-auth/types.js +4 -0
  364. package/dist/better-auth/types.js.map +1 -0
  365. package/dist/index.d.ts +1 -0
  366. package/dist/index.js +4 -0
  367. package/dist/index.js.map +1 -0
  368. package/dist/shared/components/icons.d.ts +7 -0
  369. package/dist/shared/components/icons.js +442 -0
  370. package/dist/shared/components/icons.js.map +1 -0
  371. package/dist/shared/components/logo.d.ts +3 -0
  372. package/dist/shared/components/logo.js +24 -0
  373. package/dist/shared/components/logo.js.map +1 -0
  374. package/dist/shared/form/components/submit.d.ts +7 -0
  375. package/dist/shared/form/components/submit.js +16 -0
  376. package/dist/shared/form/components/submit.js.map +1 -0
  377. package/dist/shared/form/fields/text-field.d.ts +8 -0
  378. package/dist/shared/form/fields/text-field.js +37 -0
  379. package/dist/shared/form/fields/text-field.js.map +1 -0
  380. package/dist/shared/form/index.d.ts +4 -0
  381. package/dist/shared/form/index.js +8 -0
  382. package/dist/shared/form/index.js.map +1 -0
  383. package/dist/shared/form/ui/header/index.d.ts +8 -0
  384. package/dist/shared/form/ui/header/index.js +24 -0
  385. package/dist/shared/form/ui/header/index.js.map +1 -0
  386. package/dist/shared/form/ui/index.d.ts +31 -0
  387. package/dist/shared/form/ui/index.js +57 -0
  388. package/dist/shared/form/ui/index.js.map +1 -0
  389. package/dist/shared/form/validation.d.ts +51 -0
  390. package/dist/shared/form/validation.js +127 -0
  391. package/dist/shared/form/validation.js.map +1 -0
  392. package/dist/shared/index.d.ts +2 -0
  393. package/dist/shared/index.js +4 -0
  394. package/dist/shared/index.js.map +1 -0
  395. package/dist/shared/payload/fields/field-copy-button/index.d.ts +3 -0
  396. package/dist/shared/payload/fields/field-copy-button/index.js +38 -0
  397. package/dist/shared/payload/fields/field-copy-button/index.js.map +1 -0
  398. package/dist/shared/payload/fields/generate-uuid-button/index.d.ts +3 -0
  399. package/dist/shared/payload/fields/generate-uuid-button/index.js +26 -0
  400. package/dist/shared/payload/fields/generate-uuid-button/index.js.map +1 -0
  401. package/dist/shared/payload/fields/index.d.ts +2 -0
  402. package/dist/shared/payload/fields/index.js +4 -0
  403. package/dist/shared/payload/fields/index.js.map +1 -0
  404. package/dist/shared/utils/regex.d.ts +2 -0
  405. package/dist/shared/utils/regex.js +4 -0
  406. package/dist/shared/utils/regex.js.map +1 -0
  407. package/dist/shared/utils/try-catch.d.ts +11 -0
  408. package/dist/shared/utils/try-catch.js +17 -0
  409. package/dist/shared/utils/try-catch.js.map +1 -0
  410. package/dist/shared/utils/value-or-default.d.ts +9 -0
  411. package/dist/shared/utils/value-or-default.js +12 -0
  412. package/dist/shared/utils/value-or-default.js.map +1 -0
  413. package/package.json +122 -0
@@ -0,0 +1,341 @@
1
+ import { checkPluginExists } from "@/better-auth/plugin/helpers/check-plugin-exists";
2
+ import { baModelFieldKeys, baModelKey, defaults, supportedBAPluginIds } from "../../../constants";
3
+ import { getAllRoleOptions } from "../../../helpers/get-all-roles";
4
+ import { assertAllSchemaFields, getSchemaCollectionSlug, getSchemaFieldName } from "../utils/collection-schema";
5
+ import { filterDuplicateFields } from "../utils/filter-duplicate-fields";
6
+ import { isAdminOrCurrentUserUpdateWithAllowedFields, isAdminOrCurrentUserWithRoles, isAdminWithRoles } from "../utils/payload-access";
7
+ import { getCollectionFields } from "../utils/transform-schema-fields-to-payload";
8
+ import { betterAuthStrategy } from "./better-auth-strategy";
9
+ import { getGenerateInviteUrlEndpoint, getRefreshTokenEndpoint, getSendInviteUrlEndpoint, getSetAdminRoleEndpoint } from "./endpoints";
10
+ import { getAfterLoginHook, getAfterLogoutHook, getBeforeDeleteHook, getBeforeLoginHook, getOnVerifiedChangeHook, getSyncAccountHook } from "./hooks";
11
+ export function buildUsersCollection({ incomingCollections, pluginOptions, resolvedSchemas }) {
12
+ const userSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.user);
13
+ const passkeySlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.passkey);
14
+ const passkeyUserIdFieldName = getSchemaFieldName(resolvedSchemas, baModelKey.passkey, baModelFieldKeys.passkey.userId);
15
+ const userSchema = resolvedSchemas[baModelKey.user];
16
+ const adminRoles = pluginOptions.users?.adminRoles ?? [
17
+ defaults.adminRole
18
+ ];
19
+ const allRoleOptions = getAllRoleOptions(pluginOptions);
20
+ const hasUsernamePlugin = checkPluginExists(pluginOptions.betterAuthOptions ?? {}, supportedBAPluginIds.username);
21
+ const existingUserCollection = incomingCollections.find((collection)=>collection.slug === userSlug);
22
+ // Fields that users can update in their own profile (non-admin users)
23
+ // Admins can update any field, but regular users are restricted to these fields
24
+ const allowedFields = pluginOptions.users?.allowedFields ?? [
25
+ 'name',
26
+ 'image'
27
+ ];
28
+ const userFieldRules = [
29
+ {
30
+ condition: (field)=>field.fieldName === 'createdAt' || field.fieldName === 'updatedAt',
31
+ transform: (field)=>({
32
+ ...field,
33
+ saveToJWT: false,
34
+ admin: {
35
+ disableBulkEdit: true,
36
+ hidden: true
37
+ },
38
+ index: true,
39
+ // Using any because PayloadCMS label function receives translation function with dynamic type
40
+ label: ({ t })=>field.fieldName === 'createdAt' ? t('general:createdAt') : t('general:updatedAt')
41
+ })
42
+ }
43
+ ];
44
+ const fieldOverrides = {
45
+ role: (field)=>({
46
+ type: 'select',
47
+ options: allRoleOptions,
48
+ defaultValue: field.defaultValue ?? defaults.userRole,
49
+ saveToJWT: true,
50
+ admin: {
51
+ description: 'The role of the user'
52
+ }
53
+ }),
54
+ email: ()=>{
55
+ // Don't add email field if it already exists in the collection
56
+ // The filterDuplicateFields function will handle this, but we can skip the override
57
+ // to avoid any potential conflicts
58
+ return {
59
+ index: true,
60
+ admin: {
61
+ description: 'The email of the user'
62
+ }
63
+ };
64
+ },
65
+ emailVerified: (field)=>({
66
+ defaultValue: field.defaultValue ?? false,
67
+ saveToJWT: true,
68
+ admin: {
69
+ description: 'Whether the email of the user has been verified'
70
+ }
71
+ }),
72
+ name: ()=>({
73
+ saveToJWT: true,
74
+ admin: {
75
+ description: 'Users chosen display name'
76
+ }
77
+ }),
78
+ image: ()=>({
79
+ saveToJWT: false,
80
+ admin: {
81
+ description: 'The image of the user'
82
+ }
83
+ }),
84
+ twoFactorEnabled: ()=>({
85
+ defaultValue: false,
86
+ admin: {
87
+ description: 'Whether the user has two factor authentication enabled',
88
+ components: {
89
+ Field: {
90
+ path: 'payload-auth/better-auth/plugin/client#TwoFactorAuth'
91
+ }
92
+ }
93
+ }
94
+ }),
95
+ username: ()=>({
96
+ admin: {
97
+ description: 'The username of the user'
98
+ }
99
+ }),
100
+ displayUsername: ()=>({
101
+ admin: {
102
+ description: 'The display username of the user'
103
+ }
104
+ }),
105
+ isAnonymous: ()=>({
106
+ defaultValue: false,
107
+ admin: {
108
+ description: 'Whether the user is anonymous.'
109
+ }
110
+ }),
111
+ phoneNumber: ()=>({
112
+ admin: {
113
+ description: 'The phone number of the user'
114
+ }
115
+ }),
116
+ phoneNumberVerified: ()=>({
117
+ defaultValue: false,
118
+ admin: {
119
+ description: 'Whether the phone number of the user has been verified'
120
+ }
121
+ }),
122
+ banned: ()=>({
123
+ defaultValue: false,
124
+ admin: {
125
+ description: 'Whether the user is banned from the platform'
126
+ }
127
+ }),
128
+ banReason: ()=>({
129
+ admin: {
130
+ description: 'The reason for the ban'
131
+ }
132
+ }),
133
+ banExpires: ()=>({
134
+ admin: {
135
+ description: 'The date and time when the ban will expire'
136
+ }
137
+ }),
138
+ normalizedEmail: ()=>({
139
+ admin: {
140
+ readOnly: true,
141
+ description: 'The normalized email of the user'
142
+ }
143
+ }),
144
+ stripeCustomerId: ()=>({
145
+ admin: {
146
+ readOnly: true,
147
+ description: 'The Stripe customer ID of the user'
148
+ }
149
+ })
150
+ };
151
+ // Get collection fields from Better Auth schema
152
+ let collectionFields = getCollectionFields({
153
+ schema: userSchema,
154
+ fieldRules: userFieldRules,
155
+ additionalProperties: fieldOverrides
156
+ });
157
+ // Pre-filter email field if it already exists in the collection
158
+ // This is a safety check before the main filterDuplicateFields call
159
+ if (existingUserCollection?.fields) {
160
+ const hasEmailField = existingUserCollection.fields.some((field)=>{
161
+ if ('name' in field && field.name === 'email') {
162
+ return true;
163
+ }
164
+ if (field.custom && typeof field.custom === 'object' && 'betterAuthFieldKey' in field.custom && field.custom.betterAuthFieldKey === 'email') {
165
+ return true;
166
+ }
167
+ return false;
168
+ });
169
+ if (hasEmailField && collectionFields) {
170
+ collectionFields = collectionFields.filter((field)=>{
171
+ if ('name' in field && field.name === 'email') {
172
+ // Check if this is the Better Auth email field
173
+ if (field.custom && typeof field.custom === 'object' && 'betterAuthFieldKey' in field.custom && field.custom.betterAuthFieldKey === 'email') {
174
+ return false; // Filter out Better Auth's email field
175
+ }
176
+ }
177
+ return true;
178
+ });
179
+ }
180
+ }
181
+ let usersCollection = {
182
+ ...existingUserCollection,
183
+ slug: userSlug,
184
+ admin: {
185
+ defaultColumns: [
186
+ 'email'
187
+ ],
188
+ useAsTitle: 'email',
189
+ group: pluginOptions?.collectionAdminGroup ?? 'Auth',
190
+ ...existingUserCollection?.admin,
191
+ hidden: pluginOptions.users?.hidden ?? false,
192
+ components: {
193
+ Description: {
194
+ path: 'payload-auth/better-auth/plugin/client#AdminInviteButton',
195
+ clientProps: {
196
+ roles: allRoleOptions
197
+ }
198
+ },
199
+ views: {
200
+ edit: {
201
+ adminButtons: {
202
+ tab: {
203
+ Component: {
204
+ path: 'payload-auth/better-auth/plugin/client#AdminButtons',
205
+ clientProps: {
206
+ userSlug,
207
+ baseURL: pluginOptions.betterAuthOptions?.baseURL,
208
+ basePath: pluginOptions.betterAuthOptions?.basePath
209
+ }
210
+ },
211
+ condition: ()=>{
212
+ // Only show the impersonate button if the admin plugin is enabled
213
+ return checkPluginExists(pluginOptions.betterAuthOptions ?? {}, supportedBAPluginIds.admin);
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+ }
220
+ },
221
+ access: {
222
+ admin: ({ req })=>adminRoles.includes(req.user?.role ?? 'user'),
223
+ read: isAdminOrCurrentUserWithRoles({
224
+ adminRoles,
225
+ idField: 'id'
226
+ }),
227
+ create: isAdminWithRoles({
228
+ adminRoles
229
+ }),
230
+ delete: isAdminOrCurrentUserWithRoles({
231
+ adminRoles,
232
+ idField: 'id'
233
+ }),
234
+ update: isAdminOrCurrentUserUpdateWithAllowedFields({
235
+ allowedFields,
236
+ adminRoles,
237
+ userSlug
238
+ }),
239
+ ...existingUserCollection?.access ?? {}
240
+ },
241
+ custom: {
242
+ ...existingUserCollection?.custom ?? {},
243
+ betterAuthModelKey: baModelKey.user
244
+ },
245
+ endpoints: [
246
+ ...existingUserCollection?.endpoints ? existingUserCollection.endpoints : [],
247
+ getRefreshTokenEndpoint(userSlug),
248
+ getSetAdminRoleEndpoint(pluginOptions, userSlug),
249
+ getGenerateInviteUrlEndpoint({
250
+ roles: allRoleOptions,
251
+ pluginOptions
252
+ }),
253
+ getSendInviteUrlEndpoint(pluginOptions)
254
+ ],
255
+ hooks: {
256
+ beforeChange: [
257
+ ...existingUserCollection?.hooks?.beforeChange ?? [],
258
+ ...pluginOptions.disableDefaultPayloadAuth ? [] : [
259
+ getOnVerifiedChangeHook()
260
+ ]
261
+ ],
262
+ afterChange: [
263
+ ...existingUserCollection?.hooks?.afterChange ?? [],
264
+ ...pluginOptions.disableDefaultPayloadAuth ? [] : [
265
+ getSyncAccountHook()
266
+ ]
267
+ ],
268
+ beforeLogin: [
269
+ ...existingUserCollection?.hooks?.beforeLogin ?? [],
270
+ ...pluginOptions.disableDefaultPayloadAuth ? [] : [
271
+ getBeforeLoginHook(pluginOptions.betterAuthOptions ?? {})
272
+ ]
273
+ ],
274
+ afterLogin: [
275
+ ...existingUserCollection?.hooks?.afterLogin ?? [],
276
+ ...pluginOptions.disableDefaultPayloadAuth ? [] : [
277
+ getAfterLoginHook()
278
+ ]
279
+ ],
280
+ afterLogout: [
281
+ ...existingUserCollection?.hooks?.afterLogout ?? [],
282
+ getAfterLogoutHook()
283
+ ],
284
+ beforeDelete: [
285
+ ...existingUserCollection?.hooks?.beforeDelete ?? [],
286
+ getBeforeDeleteHook()
287
+ ]
288
+ },
289
+ auth: {
290
+ ...existingUserCollection && typeof existingUserCollection.auth === 'object' ? existingUserCollection.auth : {},
291
+ ...pluginOptions.disableDefaultPayloadAuth && {
292
+ disableLocalStrategy: true
293
+ },
294
+ ...hasUsernamePlugin && {
295
+ loginWithUsername: {
296
+ allowEmailLogin: true,
297
+ requireEmail: true,
298
+ requireUsername: false
299
+ }
300
+ },
301
+ strategies: [
302
+ betterAuthStrategy(userSlug)
303
+ ]
304
+ },
305
+ fields: [
306
+ ...existingUserCollection?.fields ?? [],
307
+ // Filter out fields that already exist to prevent duplicates
308
+ // Check both by name and betterAuthFieldKey to catch all duplicates
309
+ // This is critical to prevent "DuplicateFieldName" errors from PayloadCMS
310
+ ...collectionFields ? filterDuplicateFields(existingUserCollection?.fields, collectionFields) : [],
311
+ ...checkPluginExists(pluginOptions.betterAuthOptions ?? {}, supportedBAPluginIds.passkey) ? [
312
+ {
313
+ name: 'managePasskeys',
314
+ type: 'ui',
315
+ admin: {
316
+ disableBulkEdit: true,
317
+ components: {
318
+ Field: {
319
+ path: 'payload-auth/better-auth/plugin/rsc#Passkeys',
320
+ serverProps: {
321
+ passkeyUserIdFieldName,
322
+ passkeySlug,
323
+ pluginOptions
324
+ }
325
+ }
326
+ }
327
+ }
328
+ }
329
+ ] : []
330
+ ]
331
+ };
332
+ if (pluginOptions.users?.collectionOverrides) {
333
+ usersCollection = pluginOptions.users.collectionOverrides({
334
+ collection: usersCollection
335
+ });
336
+ }
337
+ assertAllSchemaFields(usersCollection, userSchema);
338
+ return usersCollection;
339
+ }
340
+
341
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/better-auth/plugin/lib/build-collections/users/index.ts"],"sourcesContent":["import { checkPluginExists } from '@/better-auth/plugin/helpers/check-plugin-exists';\nimport { baModelFieldKeys, baModelKey, defaults, supportedBAPluginIds } from '../../../constants';\nimport { getAllRoleOptions } from '../../../helpers/get-all-roles';\nimport {\n assertAllSchemaFields,\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from '../utils/collection-schema';\nimport { filterDuplicateFields } from '../utils/filter-duplicate-fields';\nimport {\n isAdminOrCurrentUserUpdateWithAllowedFields,\n isAdminOrCurrentUserWithRoles,\n isAdminWithRoles,\n} from '../utils/payload-access';\nimport { getCollectionFields } from '../utils/transform-schema-fields-to-payload';\nimport { betterAuthStrategy } from './better-auth-strategy';\nimport {\n getGenerateInviteUrlEndpoint,\n getRefreshTokenEndpoint,\n getSendInviteUrlEndpoint,\n getSetAdminRoleEndpoint,\n} from './endpoints';\nimport {\n getAfterLoginHook,\n getAfterLogoutHook,\n getBeforeDeleteHook,\n getBeforeLoginHook,\n getOnVerifiedChangeHook,\n getSyncAccountHook,\n} from './hooks';\n\nimport type { User } from '@/better-auth/generated-types';\nimport type { CollectionConfig, Field, UIField } from 'payload';\nimport type { BuildCollectionProps, FieldOverrides, FieldRule } from '../../../types';\n\nexport function buildUsersCollection({\n incomingCollections,\n pluginOptions,\n resolvedSchemas,\n}: BuildCollectionProps): CollectionConfig {\n const userSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.user);\n const passkeySlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.passkey);\n const passkeyUserIdFieldName = getSchemaFieldName(\n resolvedSchemas,\n baModelKey.passkey,\n baModelFieldKeys.passkey.userId\n );\n const userSchema = resolvedSchemas[baModelKey.user];\n const adminRoles = pluginOptions.users?.adminRoles ?? [defaults.adminRole];\n const allRoleOptions = getAllRoleOptions(pluginOptions);\n const hasUsernamePlugin = checkPluginExists(\n pluginOptions.betterAuthOptions ?? {},\n supportedBAPluginIds.username\n );\n const existingUserCollection = incomingCollections.find(\n collection => collection.slug === userSlug\n ) as CollectionConfig | undefined;\n\n // Fields that users can update in their own profile (non-admin users)\n // Admins can update any field, but regular users are restricted to these fields\n const allowedFields = pluginOptions.users?.allowedFields ?? ['name', 'image'];\n\n const userFieldRules: FieldRule[] = [\n {\n condition: field => field.fieldName === 'createdAt' || field.fieldName === 'updatedAt',\n transform: field => ({\n ...field,\n saveToJWT: false,\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n index: true,\n // Using any because PayloadCMS label function receives translation function with dynamic type\n label: ({ t }: any) =>\n field.fieldName === 'createdAt' ? t('general:createdAt') : t('general:updatedAt'),\n }),\n },\n ];\n\n const fieldOverrides: FieldOverrides<keyof User> = {\n role: field => ({\n type: 'select',\n options: allRoleOptions,\n defaultValue: field.defaultValue ?? defaults.userRole,\n saveToJWT: true,\n admin: { description: 'The role of the user' },\n }),\n email: () => {\n // Don't add email field if it already exists in the collection\n // The filterDuplicateFields function will handle this, but we can skip the override\n // to avoid any potential conflicts\n return {\n index: true,\n admin: { description: 'The email of the user' },\n };\n },\n emailVerified: field => ({\n defaultValue: field.defaultValue ?? false,\n saveToJWT: true,\n admin: { description: 'Whether the email of the user has been verified' },\n }),\n name: () => ({\n saveToJWT: true,\n admin: { description: 'Users chosen display name' },\n }),\n image: () => ({\n saveToJWT: false,\n admin: { description: 'The image of the user' },\n }),\n twoFactorEnabled: () => ({\n defaultValue: false,\n admin: {\n description: 'Whether the user has two factor authentication enabled',\n components: {\n Field: {\n path: 'payload-auth/better-auth/plugin/client#TwoFactorAuth',\n },\n },\n },\n }),\n username: () => ({\n admin: { description: 'The username of the user' },\n }),\n displayUsername: () => ({\n admin: { description: 'The display username of the user' },\n }),\n isAnonymous: () => ({\n defaultValue: false,\n admin: { description: 'Whether the user is anonymous.' },\n }),\n phoneNumber: () => ({\n admin: { description: 'The phone number of the user' },\n }),\n phoneNumberVerified: () => ({\n defaultValue: false,\n admin: { description: 'Whether the phone number of the user has been verified' },\n }),\n banned: () => ({\n defaultValue: false,\n admin: { description: 'Whether the user is banned from the platform' },\n }),\n banReason: () => ({\n admin: { description: 'The reason for the ban' },\n }),\n banExpires: () => ({\n admin: { description: 'The date and time when the ban will expire' },\n }),\n normalizedEmail: () => ({\n admin: {\n readOnly: true,\n description: 'The normalized email of the user',\n },\n }),\n stripeCustomerId: () => ({\n admin: {\n readOnly: true,\n description: 'The Stripe customer ID of the user',\n },\n }),\n };\n\n // Get collection fields from Better Auth schema\n let collectionFields = getCollectionFields({\n schema: userSchema,\n fieldRules: userFieldRules,\n additionalProperties: fieldOverrides,\n });\n\n // Pre-filter email field if it already exists in the collection\n // This is a safety check before the main filterDuplicateFields call\n if (existingUserCollection?.fields) {\n const hasEmailField = existingUserCollection.fields.some((field: Field) => {\n if ('name' in field && field.name === 'email') {\n return true;\n }\n if (\n field.custom &&\n typeof field.custom === 'object' &&\n 'betterAuthFieldKey' in field.custom &&\n (field.custom as { betterAuthFieldKey: string }).betterAuthFieldKey === 'email'\n ) {\n return true;\n }\n return false;\n });\n\n if (hasEmailField && collectionFields) {\n collectionFields = collectionFields.filter((field: Field) => {\n if ('name' in field && field.name === 'email') {\n // Check if this is the Better Auth email field\n if (\n field.custom &&\n typeof field.custom === 'object' &&\n 'betterAuthFieldKey' in field.custom &&\n (field.custom as { betterAuthFieldKey: string }).betterAuthFieldKey === 'email'\n ) {\n return false; // Filter out Better Auth's email field\n }\n }\n return true;\n });\n }\n }\n\n let usersCollection: CollectionConfig = {\n ...existingUserCollection,\n slug: userSlug,\n admin: {\n defaultColumns: ['email'],\n useAsTitle: 'email',\n group: pluginOptions?.collectionAdminGroup ?? 'Auth',\n ...existingUserCollection?.admin,\n hidden: pluginOptions.users?.hidden ?? false,\n components: {\n Description: {\n path: 'payload-auth/better-auth/plugin/client#AdminInviteButton',\n clientProps: {\n roles: allRoleOptions,\n },\n },\n views: {\n edit: {\n adminButtons: {\n tab: {\n Component: {\n path: 'payload-auth/better-auth/plugin/client#AdminButtons',\n clientProps: {\n userSlug,\n baseURL: pluginOptions.betterAuthOptions?.baseURL,\n basePath: pluginOptions.betterAuthOptions?.basePath,\n },\n },\n condition: () => {\n // Only show the impersonate button if the admin plugin is enabled\n return checkPluginExists(\n pluginOptions.betterAuthOptions ?? {},\n supportedBAPluginIds.admin\n );\n },\n },\n },\n },\n },\n },\n },\n access: {\n admin: ({ req }) => adminRoles.includes((req.user?.role as string) ?? 'user'),\n read: isAdminOrCurrentUserWithRoles({ adminRoles, idField: 'id' }),\n create: isAdminWithRoles({ adminRoles }),\n delete: isAdminOrCurrentUserWithRoles({ adminRoles, idField: 'id' }),\n update: isAdminOrCurrentUserUpdateWithAllowedFields({\n allowedFields,\n adminRoles,\n userSlug,\n }),\n ...(existingUserCollection?.access ?? {}),\n },\n custom: {\n ...(existingUserCollection?.custom ?? {}),\n betterAuthModelKey: baModelKey.user,\n },\n endpoints: [\n ...(existingUserCollection?.endpoints ? existingUserCollection.endpoints : []),\n getRefreshTokenEndpoint(userSlug),\n getSetAdminRoleEndpoint(pluginOptions, userSlug),\n getGenerateInviteUrlEndpoint({\n roles: allRoleOptions,\n pluginOptions,\n }),\n getSendInviteUrlEndpoint(pluginOptions),\n ],\n hooks: {\n beforeChange: [\n ...(existingUserCollection?.hooks?.beforeChange ?? []),\n ...(pluginOptions.disableDefaultPayloadAuth ? [] : [getOnVerifiedChangeHook()]),\n ],\n afterChange: [\n ...(existingUserCollection?.hooks?.afterChange ?? []),\n ...(pluginOptions.disableDefaultPayloadAuth ? [] : [getSyncAccountHook()]),\n ],\n beforeLogin: [\n ...(existingUserCollection?.hooks?.beforeLogin ?? []),\n ...(pluginOptions.disableDefaultPayloadAuth\n ? []\n : [getBeforeLoginHook(pluginOptions.betterAuthOptions ?? {})]),\n ],\n afterLogin: [\n ...(existingUserCollection?.hooks?.afterLogin ?? []),\n ...(pluginOptions.disableDefaultPayloadAuth ? [] : [getAfterLoginHook()]),\n ],\n afterLogout: [...(existingUserCollection?.hooks?.afterLogout ?? []), getAfterLogoutHook()],\n beforeDelete: [...(existingUserCollection?.hooks?.beforeDelete ?? []), getBeforeDeleteHook()],\n },\n auth: {\n ...(existingUserCollection && typeof existingUserCollection.auth === 'object'\n ? existingUserCollection.auth\n : {}),\n ...(pluginOptions.disableDefaultPayloadAuth && { disableLocalStrategy: true }),\n ...(hasUsernamePlugin && {\n loginWithUsername: {\n allowEmailLogin: true,\n requireEmail: true,\n requireUsername: false,\n },\n }),\n strategies: [betterAuthStrategy(userSlug)],\n },\n fields: [\n ...(existingUserCollection?.fields ?? []),\n // Filter out fields that already exist to prevent duplicates\n // Check both by name and betterAuthFieldKey to catch all duplicates\n // This is critical to prevent \"DuplicateFieldName\" errors from PayloadCMS\n ...(collectionFields\n ? filterDuplicateFields(existingUserCollection?.fields, collectionFields)\n : []),\n ...(checkPluginExists(pluginOptions.betterAuthOptions ?? {}, supportedBAPluginIds.passkey)\n ? [\n {\n name: 'managePasskeys',\n type: 'ui' as const,\n admin: {\n disableBulkEdit: true,\n components: {\n Field: {\n path: 'payload-auth/better-auth/plugin/rsc#Passkeys',\n serverProps: {\n passkeyUserIdFieldName,\n passkeySlug,\n pluginOptions,\n },\n },\n },\n },\n } as UIField,\n ]\n : []),\n ],\n };\n\n if (pluginOptions.users?.collectionOverrides) {\n usersCollection = pluginOptions.users.collectionOverrides({\n collection: usersCollection,\n });\n }\n\n assertAllSchemaFields(usersCollection, userSchema);\n\n return usersCollection;\n}\n"],"names":["checkPluginExists","baModelFieldKeys","baModelKey","defaults","supportedBAPluginIds","getAllRoleOptions","assertAllSchemaFields","getSchemaCollectionSlug","getSchemaFieldName","filterDuplicateFields","isAdminOrCurrentUserUpdateWithAllowedFields","isAdminOrCurrentUserWithRoles","isAdminWithRoles","getCollectionFields","betterAuthStrategy","getGenerateInviteUrlEndpoint","getRefreshTokenEndpoint","getSendInviteUrlEndpoint","getSetAdminRoleEndpoint","getAfterLoginHook","getAfterLogoutHook","getBeforeDeleteHook","getBeforeLoginHook","getOnVerifiedChangeHook","getSyncAccountHook","buildUsersCollection","incomingCollections","pluginOptions","resolvedSchemas","userSlug","user","passkeySlug","passkey","passkeyUserIdFieldName","userId","userSchema","adminRoles","users","adminRole","allRoleOptions","hasUsernamePlugin","betterAuthOptions","username","existingUserCollection","find","collection","slug","allowedFields","userFieldRules","condition","field","fieldName","transform","saveToJWT","admin","disableBulkEdit","hidden","index","label","t","fieldOverrides","role","type","options","defaultValue","userRole","description","email","emailVerified","name","image","twoFactorEnabled","components","Field","path","displayUsername","isAnonymous","phoneNumber","phoneNumberVerified","banned","banReason","banExpires","normalizedEmail","readOnly","stripeCustomerId","collectionFields","schema","fieldRules","additionalProperties","fields","hasEmailField","some","custom","betterAuthFieldKey","filter","usersCollection","defaultColumns","useAsTitle","group","collectionAdminGroup","Description","clientProps","roles","views","edit","adminButtons","tab","Component","baseURL","basePath","access","req","includes","read","idField","create","delete","update","betterAuthModelKey","endpoints","hooks","beforeChange","disableDefaultPayloadAuth","afterChange","beforeLogin","afterLogin","afterLogout","beforeDelete","auth","disableLocalStrategy","loginWithUsername","allowEmailLogin","requireEmail","requireUsername","strategies","serverProps","collectionOverrides"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,mDAAmD;AACrF,SAASC,gBAAgB,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,oBAAoB,QAAQ,qBAAqB;AAClG,SAASC,iBAAiB,QAAQ,iCAAiC;AACnE,SACEC,qBAAqB,EACrBC,uBAAuB,EACvBC,kBAAkB,QACb,6BAA6B;AACpC,SAASC,qBAAqB,QAAQ,mCAAmC;AACzE,SACEC,2CAA2C,EAC3CC,6BAA6B,EAC7BC,gBAAgB,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AAwB8C,UAAU,EAAE;YACxC,6DAA6D;YAC7D,oEAAoE;YACpE,0EAA0E;eACtEJ,mBACA5E,sBAAsBkC,wBAAwB8C,QAAQJ,oBACtD,EAAE;eACFrF,kBAAkB2B,cAAcc,iBAAiB,IAAI,CAAC,GAAGrC,qBAAqB4B,OAAO,IACrF;gBACE;oBACEqC,MAAM;oBACNP,MAAM;oBACNR,OAAO;wBACLC,iBAAiB;wBACjBiB,YAAY;4BACVC,OAAO;gCACLC,MAAM;gCACN6D,aAAa;oCACXtG;oCACAF;oCACAJ;gCACF;4BACF;wBACF;oBACF;gBACF;aACD,GACD,EAAE;SACP;IACH;IAEA,IAAIA,cAAcU,KAAK,EAAEmG,qBAAqB;QAC5CzC,kBAAkBpE,cAAcU,KAAK,CAACmG,mBAAmB,CAAC;YACxD3F,YAAYkD;QACd;IACF;IAEAzF,sBAAsByF,iBAAiB5D;IAEvC,OAAO4D;AACT"}
@@ -0,0 +1,15 @@
1
+ import type { BetterAuthFullSchema, ModelKey } from '@/better-auth/generated-types';
2
+ import type { BetterAuthSchemas, BuiltBetterAuthSchema } from '@/better-auth/types';
3
+ import { type CollectionConfig } from 'payload';
4
+ export declare function getSchemaCollectionSlug(resolvedSchemas: BetterAuthSchemas, model: ModelKey): string;
5
+ export declare function getSchemaFieldName<M extends ModelKey>(resolvedSchemas: BetterAuthSchemas, model: M, fieldKey: Extract<keyof BetterAuthFullSchema[M], string>): string;
6
+ /**
7
+ * Asserts that all field keys that exist in the schema exist in the collection
8
+ *
9
+ * It checks based on the custom.betterAuthFieldKey property.
10
+ *
11
+ * @param collection - The collection object
12
+ * @param schema - The schema object containing field definitions
13
+ * @throws {Error} If any required field is missing from the schema
14
+ */
15
+ export declare function assertAllSchemaFields(collection: CollectionConfig, schema: BuiltBetterAuthSchema): void;
@@ -0,0 +1,24 @@
1
+ import { flattenAllFields } from "payload";
2
+ export function getSchemaCollectionSlug(resolvedSchemas, model) {
3
+ return resolvedSchemas?.[model]?.modelName ?? model;
4
+ }
5
+ export function getSchemaFieldName(resolvedSchemas, model, fieldKey) {
6
+ return resolvedSchemas?.[model]?.fields?.[fieldKey]?.fieldName ?? fieldKey;
7
+ }
8
+ /**
9
+ * Asserts that all field keys that exist in the schema exist in the collection
10
+ *
11
+ * It checks based on the custom.betterAuthFieldKey property.
12
+ *
13
+ * @param collection - The collection object
14
+ * @param schema - The schema object containing field definitions
15
+ * @throws {Error} If any required field is missing from the schema
16
+ */ export function assertAllSchemaFields(collection, schema) {
17
+ const schemaFieldKeys = Object.keys(schema.fields);
18
+ const collectionConfigBetterAuthKeys = new Set(flattenAllFields(collection).map((field)=>field.custom?.betterAuthFieldKey).filter((key)=>typeof key === 'string'));
19
+ const missingFields = schemaFieldKeys.filter((key)=>!collectionConfigBetterAuthKeys.has(key));
20
+ if (missingFields.length === 0) return;
21
+ throw new Error(`Missing required custom.betterAuthFieldKeys in collection "${collection.slug}": ${missingFields.join(', ')}`);
22
+ }
23
+
24
+ //# sourceMappingURL=collection-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/better-auth/plugin/lib/build-collections/utils/collection-schema.ts"],"sourcesContent":["import type { BetterAuthFullSchema, ModelKey } from '@/better-auth/generated-types';\nimport type { BetterAuthSchemas, BuiltBetterAuthSchema } from '@/better-auth/types';\nimport { type CollectionConfig, flattenAllFields } from 'payload';\n\nexport function getSchemaCollectionSlug(\n resolvedSchemas: BetterAuthSchemas,\n model: ModelKey\n): string {\n return resolvedSchemas?.[model]?.modelName ?? model;\n}\n\nexport function getSchemaFieldName<M extends ModelKey>(\n resolvedSchemas: BetterAuthSchemas,\n model: M,\n fieldKey: Extract<keyof BetterAuthFullSchema[M], string>\n): string {\n return resolvedSchemas?.[model]?.fields?.[fieldKey]?.fieldName ?? fieldKey;\n}\n\n/**\n * Asserts that all field keys that exist in the schema exist in the collection\n *\n * It checks based on the custom.betterAuthFieldKey property.\n *\n * @param collection - The collection object\n * @param schema - The schema object containing field definitions\n * @throws {Error} If any required field is missing from the schema\n */\n\nexport function assertAllSchemaFields(\n collection: CollectionConfig,\n schema: BuiltBetterAuthSchema\n): void {\n const schemaFieldKeys = Object.keys(schema.fields);\n const collectionConfigBetterAuthKeys = new Set(\n flattenAllFields(collection)\n .map(field => field.custom?.betterAuthFieldKey)\n .filter((key): key is string => typeof key === 'string')\n );\n\n const missingFields = schemaFieldKeys.filter(key => !collectionConfigBetterAuthKeys.has(key));\n if (missingFields.length === 0) return;\n\n throw new Error(\n `Missing required custom.betterAuthFieldKeys in collection \"${collection.slug}\": ${missingFields.join(', ')}`\n );\n}\n"],"names":["flattenAllFields","getSchemaCollectionSlug","resolvedSchemas","model","modelName","getSchemaFieldName","fieldKey","fields","fieldName","assertAllSchemaFields","collection","schema","schemaFieldKeys","Object","keys","collectionConfigBetterAuthKeys","Set","map","field","custom","betterAuthFieldKey","filter","key","missingFields","has","length","Error","slug","join"],"mappings":"AAEA,SAAgCA,gBAAgB,QAAQ,UAAU;AAElE,OAAO,SAASC,wBACdC,eAAkC,EAClCC,KAAe;IAEf,OAAOD,iBAAiB,CAACC,MAAM,EAAEC,aAAaD;AAChD;AAEA,OAAO,SAASE,mBACdH,eAAkC,EAClCC,KAAQ,EACRG,QAAwD;IAExD,OAAOJ,iBAAiB,CAACC,MAAM,EAAEI,QAAQ,CAACD,SAAS,EAAEE,aAAaF;AACpE;AAEA;;;;;;;;CAQC,GAED,OAAO,SAASG,sBACdC,UAA4B,EAC5BC,MAA6B;IAE7B,MAAMC,kBAAkBC,OAAOC,IAAI,CAACH,OAAOJ,MAAM;IACjD,MAAMQ,iCAAiC,IAAIC,IACzChB,iBAAiBU,YACdO,GAAG,CAACC,CAAAA,QAASA,MAAMC,MAAM,EAAEC,oBAC3BC,MAAM,CAAC,CAACC,MAAuB,OAAOA,QAAQ;IAGnD,MAAMC,gBAAgBX,gBAAgBS,MAAM,CAACC,CAAAA,MAAO,CAACP,+BAA+BS,GAAG,CAACF;IACxF,IAAIC,cAAcE,MAAM,KAAK,GAAG;IAEhC,MAAM,IAAIC,MACR,CAAC,2DAA2D,EAAEhB,WAAWiB,IAAI,CAAC,GAAG,EAAEJ,cAAcK,IAAI,CAAC,OAAO;AAEjH"}
@@ -0,0 +1,10 @@
1
+ import type { Field } from 'payload';
2
+ /**
3
+ * Filters out fields from newFields that already exist in existingFields by name
4
+ * This prevents duplicate field errors when merging existing collection fields with Better Auth schema fields
5
+ *
6
+ * @param existingFields - Fields that already exist in the collection
7
+ * @param newFields - New fields to add from Better Auth schema
8
+ * @returns Filtered array of new fields that don't conflict with existing fields
9
+ */
10
+ export declare function filterDuplicateFields(existingFields: Field[] | undefined, newFields: Field[] | null | undefined): Field[];
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Filters out fields from newFields that already exist in existingFields by name
3
+ * This prevents duplicate field errors when merging existing collection fields with Better Auth schema fields
4
+ *
5
+ * @param existingFields - Fields that already exist in the collection
6
+ * @param newFields - New fields to add from Better Auth schema
7
+ * @returns Filtered array of new fields that don't conflict with existing fields
8
+ */ export function filterDuplicateFields(existingFields, newFields) {
9
+ if (!newFields || !Array.isArray(newFields)) {
10
+ return [];
11
+ }
12
+ if (!existingFields || !Array.isArray(existingFields)) {
13
+ return newFields;
14
+ }
15
+ // Create Sets for O(1) lookup - check both by name and betterAuthFieldKey
16
+ const existingFieldNames = new Set();
17
+ const existingBetterAuthKeys = new Set();
18
+ // Recursively collect all field names and betterAuthFieldKeys from existing fields
19
+ const collectFieldInfo = (fields)=>{
20
+ for (const field of fields){
21
+ if (field.name) {
22
+ existingFieldNames.add(field.name);
23
+ }
24
+ // Also check for betterAuthFieldKey to prevent duplicates even if names differ
25
+ if (field.custom && typeof field.custom === 'object' && 'betterAuthFieldKey' in field.custom) {
26
+ const betterAuthKey = field.custom.betterAuthFieldKey;
27
+ if (typeof betterAuthKey === 'string') {
28
+ existingBetterAuthKeys.add(betterAuthKey);
29
+ }
30
+ }
31
+ // Also check nested fields in groups, arrays, etc.
32
+ if ('fields' in field && Array.isArray(field.fields)) {
33
+ collectFieldInfo(field.fields);
34
+ }
35
+ // Check tabs
36
+ if ('tabs' in field && Array.isArray(field.tabs)) {
37
+ for (const tab of field.tabs){
38
+ if (tab.fields && Array.isArray(tab.fields)) {
39
+ collectFieldInfo(tab.fields);
40
+ }
41
+ }
42
+ }
43
+ }
44
+ };
45
+ collectFieldInfo(existingFields);
46
+ // Filter out fields that already exist (by name OR by betterAuthFieldKey)
47
+ return newFields.filter((field)=>{
48
+ if (!field.name) {
49
+ // Keep fields without names (like UI fields, collapsibles, etc.)
50
+ return true;
51
+ }
52
+ // Check if field name already exists
53
+ if (existingFieldNames.has(field.name)) {
54
+ return false;
55
+ }
56
+ // Also check if betterAuthFieldKey already exists (prevents duplicates even with different names)
57
+ if (field.custom && typeof field.custom === 'object' && 'betterAuthFieldKey' in field.custom) {
58
+ const betterAuthKey = field.custom.betterAuthFieldKey;
59
+ if (typeof betterAuthKey === 'string' && existingBetterAuthKeys.has(betterAuthKey)) {
60
+ return false;
61
+ }
62
+ }
63
+ return true;
64
+ });
65
+ }
66
+
67
+ //# sourceMappingURL=filter-duplicate-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.ts"],"sourcesContent":["import type {Field} from 'payload';\n\n/**\n * Filters out fields from newFields that already exist in existingFields by name\n * This prevents duplicate field errors when merging existing collection fields with Better Auth schema fields\n *\n * @param existingFields - Fields that already exist in the collection\n * @param newFields - New fields to add from Better Auth schema\n * @returns Filtered array of new fields that don't conflict with existing fields\n */\nexport function filterDuplicateFields(\n existingFields: Field[] | undefined,\n newFields: Field[] | null | undefined\n): Field[] {\n if (!newFields || !Array.isArray(newFields)) {\n return [];\n }\n\n if (!existingFields || !Array.isArray(existingFields)) {\n return newFields;\n }\n\n // Create Sets for O(1) lookup - check both by name and betterAuthFieldKey\n const existingFieldNames = new Set<string>();\n const existingBetterAuthKeys = new Set<string>();\n\n // Recursively collect all field names and betterAuthFieldKeys from existing fields\n const collectFieldInfo = (fields: Field[]): void => {\n for (const field of fields) {\n if (field.name) {\n existingFieldNames.add(field.name);\n }\n // Also check for betterAuthFieldKey to prevent duplicates even if names differ\n if (field.custom && typeof field.custom === 'object' && 'betterAuthFieldKey' in field.custom) {\n const betterAuthKey = field.custom.betterAuthFieldKey;\n if (typeof betterAuthKey === 'string') {\n existingBetterAuthKeys.add(betterAuthKey);\n }\n }\n // Also check nested fields in groups, arrays, etc.\n if ('fields' in field && Array.isArray(field.fields)) {\n collectFieldInfo(field.fields);\n }\n // Check tabs\n if ('tabs' in field && Array.isArray(field.tabs)) {\n for (const tab of field.tabs) {\n if (tab.fields && Array.isArray(tab.fields)) {\n collectFieldInfo(tab.fields);\n }\n }\n }\n }\n };\n\n collectFieldInfo(existingFields);\n\n // Filter out fields that already exist (by name OR by betterAuthFieldKey)\n return newFields.filter(field => {\n if (!field.name) {\n // Keep fields without names (like UI fields, collapsibles, etc.)\n return true;\n }\n \n // Check if field name already exists\n if (existingFieldNames.has(field.name)) {\n return false;\n }\n \n // Also check if betterAuthFieldKey already exists (prevents duplicates even with different names)\n if (field.custom && typeof field.custom === 'object' && 'betterAuthFieldKey' in field.custom) {\n const betterAuthKey = field.custom.betterAuthFieldKey;\n if (typeof betterAuthKey === 'string' && existingBetterAuthKeys.has(betterAuthKey)) {\n return false;\n }\n }\n \n return true;\n });\n}\n"],"names":["filterDuplicateFields","existingFields","newFields","Array","isArray","existingFieldNames","Set","existingBetterAuthKeys","collectFieldInfo","fields","field","name","add","custom","betterAuthKey","betterAuthFieldKey","tabs","tab","filter","has"],"mappings":"AAEA;;;;;;;CAOC,GACD,OAAO,SAASA,sBACdC,cAAmC,EACnCC,SAAqC;IAErC,IAAI,CAACA,aAAa,CAACC,MAAMC,OAAO,CAACF,YAAY;QAC3C,OAAO,EAAE;IACX;IAEA,IAAI,CAACD,kBAAkB,CAACE,MAAMC,OAAO,CAACH,iBAAiB;QACrD,OAAOC;I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;YACrD,IAAI,OAAOD,kBAAkB,YAAYP,uBAAuBY,GAAG,CAACL,gBAAgB;gBAClF,OAAO;YACT;QACF;QAEA,OAAO;IACT;AACF"}
@@ -0,0 +1,9 @@
1
+ import type { Field } from 'payload';
2
+ export declare const COMMON_FIELD_KEYS: readonly ["access", "admin", "custom", "defaultValue", "hidden", "hooks", "index", "label", "localized", "name", "required", "saveToJWT", "typescriptSchema", "unique", "validate", "virtual", "_sanitized"];
3
+ export declare const TEXT_FIELD_KEYS: readonly ["access", "admin", "custom", "defaultValue", "hidden", "hooks", "index", "label", "localized", "name", "required", "saveToJWT", "typescriptSchema", "unique", "validate", "virtual", "_sanitized", "maxLength", "maxRows", "minLength", "minRows"];
4
+ export declare const NUMBER_FIELD_KEYS: readonly ["access", "admin", "custom", "defaultValue", "hidden", "hooks", "index", "label", "localized", "name", "required", "saveToJWT", "typescriptSchema", "unique", "validate", "virtual", "_sanitized", "max", "min"];
5
+ export declare const DATE_FIELD_KEYS: readonly ["access", "admin", "custom", "defaultValue", "hidden", "hooks", "index", "label", "localized", "name", "required", "saveToJWT", "typescriptSchema", "unique", "validate", "virtual", "_sanitized", "timezone"];
6
+ export declare const CHECKBOX_FIELD_KEYS: readonly ["access", "admin", "custom", "defaultValue", "hidden", "hooks", "index", "label", "localized", "name", "required", "saveToJWT", "typescriptSchema", "unique", "validate", "virtual", "_sanitized"];
7
+ export declare const RELATIONSHIP_FIELD_KEYS: readonly ["access", "admin", "custom", "defaultValue", "hidden", "hooks", "index", "label", "localized", "name", "required", "saveToJWT", "typescriptSchema", "unique", "validate", "virtual", "_sanitized", "filterOptions", "graphQL", "hasMany", "max", "maxDepth", "maxRows", "min", "minRows", "relationTo", "type"];
8
+ export declare function getValidFieldPropertyKeysForType(type: Field['type']): ("validate" | "custom" | "type" | "defaultValue" | "required" | "name" | "hooks" | "unique" | "max" | "min" | "admin" | "index" | "hidden" | "relationTo" | "label" | "_sanitized" | "access" | "localized" | "saveToJWT" | "typescriptSchema" | "virtual" | "maxRows" | "minRows" | "maxDepth" | "hasMany" | "graphQL" | "filterOptions")[] | ("validate" | "custom" | "defaultValue" | "maxLength" | "minLength" | "required" | "name" | "hooks" | "unique" | "admin" | "index" | "hidden" | "label" | "_sanitized" | "access" | "localized" | "saveToJWT" | "typescriptSchema" | "virtual" | "maxRows" | "minRows")[] | ("validate" | "custom" | "defaultValue" | "required" | "name" | "hooks" | "unique" | "admin" | "timezone" | "index" | "hidden" | "label" | "_sanitized" | "access" | "localized" | "saveToJWT" | "typescriptSchema" | "virtual")[];
9
+ export declare function filterProps<T extends object, K extends readonly (keyof T)[]>(obj: Partial<T>, allowed: K, extra?: readonly string[]): Partial<T>;
@@ -0,0 +1,94 @@
1
+ export const COMMON_FIELD_KEYS = [
2
+ 'access',
3
+ 'admin',
4
+ 'custom',
5
+ 'defaultValue',
6
+ 'hidden',
7
+ 'hooks',
8
+ 'index',
9
+ 'label',
10
+ 'localized',
11
+ 'name',
12
+ 'required',
13
+ 'saveToJWT',
14
+ 'typescriptSchema',
15
+ 'unique',
16
+ 'validate',
17
+ 'virtual',
18
+ '_sanitized'
19
+ ];
20
+ export const TEXT_FIELD_KEYS = [
21
+ ...COMMON_FIELD_KEYS,
22
+ 'maxLength',
23
+ 'maxRows',
24
+ 'minLength',
25
+ 'minRows'
26
+ ];
27
+ export const NUMBER_FIELD_KEYS = [
28
+ ...COMMON_FIELD_KEYS,
29
+ 'max',
30
+ 'min'
31
+ ];
32
+ export const DATE_FIELD_KEYS = [
33
+ ...COMMON_FIELD_KEYS,
34
+ 'timezone'
35
+ ];
36
+ export const CHECKBOX_FIELD_KEYS = [
37
+ ...COMMON_FIELD_KEYS
38
+ ];
39
+ export const RELATIONSHIP_FIELD_KEYS = [
40
+ ...COMMON_FIELD_KEYS,
41
+ 'filterOptions',
42
+ 'graphQL',
43
+ 'hasMany',
44
+ 'max',
45
+ 'maxDepth',
46
+ 'maxRows',
47
+ 'min',
48
+ 'minRows',
49
+ 'relationTo',
50
+ 'type'
51
+ ];
52
+ export function getValidFieldPropertyKeysForType(type) {
53
+ switch(type){
54
+ case 'relationship':
55
+ return [
56
+ ...RELATIONSHIP_FIELD_KEYS
57
+ ];
58
+ case 'text':
59
+ return [
60
+ ...TEXT_FIELD_KEYS
61
+ ];
62
+ case 'number':
63
+ return [
64
+ ...NUMBER_FIELD_KEYS
65
+ ];
66
+ case 'date':
67
+ return [
68
+ ...DATE_FIELD_KEYS
69
+ ];
70
+ case 'checkbox':
71
+ return [
72
+ ...CHECKBOX_FIELD_KEYS
73
+ ];
74
+ default:
75
+ return [
76
+ ...COMMON_FIELD_KEYS
77
+ ];
78
+ }
79
+ }
80
+ export function filterProps(obj, allowed, extra = []) {
81
+ const allow = new Set([
82
+ ...allowed.map(String),
83
+ ...extra
84
+ ]);
85
+ // Using Record<string, unknown> because filtered object structure varies by input object type and cannot be strictly typed
86
+ const out = {};
87
+ for (const [k, v] of Object.entries(obj)){
88
+ if (!allow.has(k)) continue;
89
+ out[k] = v;
90
+ }
91
+ return out;
92
+ }
93
+
94
+ //# sourceMappingURL=filter-properties.js.map