Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Better Auth

default discord avatar
creativefold7 months ago
15

I am trying to integrate Better-auth as part of my current payload application. any tutorials on how to do this easily?

  • default discord avatar
    creativefold7 months ago

    Any ideas if I can apply it to a custom Collection? Not 'users'?

  • default discord avatar
    oliver_012547 months ago

    Feel free to checkout the payload starter template I created with

    payload-auth

    https://github.com/fluid-design-io/payload-better-auth-starter
  • default discord avatar
    adek14497 months ago

    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?

  • default discord avatar
    oliver_012547 months ago

    No I have not, since I added roles to Better Auth which only admins can access the admin panel,

  • default discord avatar
    binaryfabric6 months ago

    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.



    https://github.com/authsmith/payload-auth-plugin

    I havent tried either yet, but I'm also looking for a better-auth solution.

  • default discord avatar
    creativefold6 months ago

    Thanks to

    @418983916771213334

    and his great work - managed to get it working perfectly.

  • default discord avatar
    binaryfabric6 months ago

    Any insights you can share that might help others (me)?

  • default discord avatar
    creativefold6 months ago

    What u having issue with?

  • default discord avatar
    binaryfabric6 months ago

    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

  • default discord avatar
    forrest.dev6 months ago

    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.

  • default discord avatar
    binaryfabric6 months ago

    Oh hey! I dont want to Hijack this thread do Ill DM

  • default discord avatar
    tago28306 months ago

    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.



    https://github.com/fluid-design-io/payload-better-auth-starter/

    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);


    Answer

    POST is not supported for default oauth providers and I had to change the config to responseMode: "query",


    https://github.com/better-auth/better-auth/issues/4327
  • default discord avatar
    luizedgar6 months ago

    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.

  • default discord avatar
    rubixvi6 months ago

    Alot of head banging and I'm rolling my own sso 😂

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.