payload CMS user sync #1995

Open
opened 2026-03-13 09:19:43 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @benjaminpreiss on GitHub (Sep 22, 2025).

Is this suited for github?

  • Yes, this is suited for github

Payload CMS authentication is very limited at the moment. Better-auth can fill the gap. A match made in heaven!

Describe the solution you'd like

I am proposing a two-sided solution through a better-auth plugin and some payload user collection tweaks.
An MVP is already implemented, documentation can be found in the README: https://github.com/benjaminpreiss/payload-better-auth

The MVP treats better-auth as the single source of truth and disables user-management in payload entirely. It syncs users from better-auth to payload on any changes detected to a better-auth user (create, update, delete), but also fully reconciles (removes discrepancies) periodically and both on startup of better-auth and payload.

Issues on the better-auth side

There are some missing pieces in the better-auth plugins interface to make the DX really great:

It would be helpful to see these features in better-auth!

What's missing?

As the changes on the payload side overwrite the authentication UI, there are also the auth UI components / screens that still have to be built, but that is more on the payload side.

Describe alternatives you've considered

Not building a plugin, but that would also not help with DX.

Additional context

No response

Originally created by @benjaminpreiss on GitHub (Sep 22, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Payload CMS authentication is very limited at the moment. Better-auth can fill the gap. A match made in heaven! ### Describe the solution you'd like I am proposing a two-sided solution through a better-auth plugin and some payload user collection tweaks. An MVP is already implemented, documentation can be found in the README: [https://github.com/benjaminpreiss/payload-better-auth](https://github.com/benjaminpreiss/payload-better-auth) The MVP treats better-auth as the single source of truth and disables user-management in payload entirely. It syncs users from better-auth to payload on any changes detected to a better-auth user (create, update, delete), but also fully reconciles (removes discrepancies) periodically and both on startup of better-auth and payload. ### Issues on the better-auth side There are some missing pieces in the better-auth plugins interface to make the DX really great: - required plugins config (if a plugin requires other plugins) - `databaseHooks` + `user.deleteUser` access within plugin + `onInit` hook with cleanup [https://github.com/better-auth/better-auth/issues/4770](https://github.com/better-auth/better-auth/issues/4770) - `databaseHooks` to allow for delete actions [https://github.com/better-auth/better-auth/issues/4766](https://github.com/better-auth/better-auth/issues/4766) It would be helpful to see these features in better-auth! ### What's missing? As the changes on the payload side overwrite the authentication UI, there are also the auth UI components / screens that still have to be built, but that is more on the payload side. ### Describe alternatives you've considered Not building a plugin, but that would also not help with DX. ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 09:19:43 -05:00
Author
Owner

@naaa760 commented on GitHub (Sep 22, 2025):

@benjaminpreiss
hello now the payload cms integration done

please let me know!

@naaa760 commented on GitHub (Sep 22, 2025): @benjaminpreiss hello now the payload cms integration done please let me know!
Author
Owner

@benjaminpreiss commented on GitHub (Sep 22, 2025):

Any chance / interest from better-auth team to add this payload integration to the official plugins?

If so, let me know what you need from me for this to happen.

@benjaminpreiss commented on GitHub (Sep 22, 2025): Any chance / interest from better-auth team to add this payload integration to the official plugins? If so, let me know what you need from me for this to happen.
Author
Owner

@benjaminpreiss commented on GitHub (Sep 22, 2025):

@naaa760 I will wait a little until the dust around the pull request has settled - but your changes look very promising!! 💯

@benjaminpreiss commented on GitHub (Sep 22, 2025): @naaa760 I will wait a little until the dust around the pull request has settled - but your changes look very promising!! 💯
Author
Owner

@benjaminpreiss commented on GitHub (Sep 23, 2025):

I have rewritten the plugin to work with the init hook: 763369a487

There is only little left to provide the best DX!

What is weird however, that on calling a custom endpoint defined by the betterAuth plugin (e.g. 763369a487/apps/payload-and-frontend/src/lib/betterAuthPlugin.ts (L80-L93)) re-executes the init code 🤔 I feel that shouldn't happen, no?

@benjaminpreiss commented on GitHub (Sep 23, 2025): I have rewritten the plugin to work with the `init` hook: https://github.com/benjaminpreiss/payload-better-auth/commit/763369a487dd3b5a379b0212b3d878b232c75524 There is only little left to provide the best DX! What is weird however, that on calling a custom endpoint defined by the betterAuth plugin (e.g. https://github.com/benjaminpreiss/payload-better-auth/blob/763369a487dd3b5a379b0212b3d878b232c75524/apps/payload-and-frontend/src/lib/betterAuthPlugin.ts#L80-L93) re-executes the `init` code 🤔 I feel that shouldn't happen, no?
Author
Owner

@dosubot[bot] commented on GitHub (Dec 23, 2025):

Hi, @benjaminpreiss. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You proposed a plugin to sync Payload CMS users with better-auth to centralize user management.
  • An MVP of the plugin exists, but improvements are needed in better-auth's plugin interface for better developer experience.
  • Authentication UI components still need to be built on Payload's side.
  • Contributor naaa760 completed the Payload CMS integration, which you acknowledged positively.
  • You rewrote the plugin to use the init hook but encountered unexpected behavior where calling a custom better-auth endpoint re-executes the init code, and you are seeking clarification on this.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • If I don’t hear back within 7 days, I will automatically close this issue to keep the backlog manageable.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Dec 23, 2025): Hi, @benjaminpreiss. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You proposed a plugin to sync Payload CMS users with better-auth to centralize user management. - An MVP of the plugin exists, but improvements are needed in better-auth's plugin interface for better developer experience. - Authentication UI components still need to be built on Payload's side. - Contributor naaa760 completed the Payload CMS integration, which you acknowledged positively. - You rewrote the plugin to use the `init` hook but encountered unexpected behavior where calling a custom better-auth endpoint re-executes the `init` code, and you are seeking clarification on this. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - If I don’t hear back within 7 days, I will automatically close this issue to keep the backlog manageable. Thanks for your understanding and contribution!
Author
Owner

@benjaminpreiss commented on GitHub (Dec 27, 2025):

This is still relevant. Waiting for an indication from the payload team to know whether this is of interest.

@benjaminpreiss commented on GitHub (Dec 27, 2025): This is still relevant. Waiting for an indication from the payload team to know whether this is of interest.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1995