I am trying to integrate Better-auth as part of my current payload application. any tutorials on how to do this easily?
I found this article to be very helpful:
Any ideas if I can apply it to a custom Collection? Not 'users'?
Feel free to checkout the payload starter template I created with
payload-authhttps://github.com/fluid-design-io/payload-better-auth-starter
Hey, by any chance did you try to use better-auth in a separate collection (like a customer) and keep the payload auth for the admin panel?
No I have not, since I added roles to Better Auth which only admins can access the admin panel,
This seems to be the preferred approach my most people. I found this plugin,
Auth-Smith, that handles it like in a separate collection but I don't think it uses better-auth, I believe they rolled their own.
I havent tried either yet, but I'm also looking for a better-auth solution.
Thanks to
@418983916771213334and his great work - managed to get it working perfectly.
Any insights you can share that might help others (me)?
What u having issue with?
Nothing in particular really as I havent started, but if you were having an issue it would be helpful to know what the issue was and how you solved it.
That being said, if I do get into an issue ill report back
The plugin does alot of heavy lifting for the most part, you just need to configure the settings correctly.
All the options are typed with some type docs on them. So just reading there can help, but otherwise any specific questions you can always drop here, to me personally or just in the GitHub repository through bugs or issues.
I do my best to answer/ respond, merge prs and maintain the plugin.
As it’s also something I wrote to use personally in production projects.
Oh hey! I dont want to Hijack this thread do Ill DM
I tried the starter but ran into issues when using a custom genericOAuth provider where it is not finding the endpoint it redirect backs to.
POST /api/auth/sign-in/oauth2
POST /api/auth/oauth2/callback/AzureAD 404 in 15ms.
I'm not sure how I can verify that the endpoint it is trying to hit is properly configured but as far as I understand it should look like the above if the providerName is AzureAD.
I tred a few things in the app/api/auth/[...all] endpoint but had the same problem regardless.
import { auth } from '@/lib/auth';
import { toNextJsHandler } from 'better-auth/next-js';
// const payload = await getPayload()
// export const { POST, GET } = toNextJsHandler(payload.betterAuth)
export const { POST, GET } = toNextJsHandler(auth.handler);POST is not supported for default oauth providers and I had to change the config to responseMode: "query",
I understand SSO is some part of Payload monetization system, but auth is so basic today! I reaaaaally like Payload, but this lack of support for basic auth, is what sometimes makes me think on not using it. Payload is amazing, I think that would unlock this project to be widely adopted for everyone wanting to build Startups, which is our case.
Alot of head banging and I'm rolling my own sso 😂
Star
Discord
online
Get dedicated engineering support directly from the Payload team.