Like what we’re doing? Star us on GitHub!

is it possible to use custom authentication

Bakry
3 weeks ago
45

s there anyway to change authentication main field from email to phone number and can i use fully custom authentication ?



@jmikrut đź‘€

  • jmikrut
    Payload Team
    2 weeks ago

    hey there - you can certainly build you own authentication patterns



    disableLocalStrategy: true


    and then you are free to use any Passport-compatible auth strategy, or you can create your own

  • Bakry
    2 weeks ago

    can you elaborate further to how can i do this exactly?



    and thank you very much

  • Arskeliss
    2 weeks ago
  • Bakry
    2 weeks ago

    the thing is



    im making a phone number/ password auth

  • Arskeliss
    2 weeks ago

    Or maybe this because this is react based

    https://github.com/ederssouza/reactjs-auth-boilerplate
  • Bakry
    2 weeks ago

    and i'm not sure how to do make a passport auth work with payload

  • Arskeliss
    2 weeks ago

    Ahm, sorry but me neither, never needed it



    But



    It's surely possible to change the default with you own component



    @Bakry

    https://github.com/payloadcms/next-auth-frontend


    Take a look at this and maybe you could rewrite it



    If you are using next as frontend



    Oh no wait, i don't know whether it will work with this

  • Bakry
    2 weeks ago

    i am not unfortunately



    tyty



    idk how to implement it in the backend tbh

  • Arskeliss
    2 weeks ago

    It needs quite of an aexperience as a developer to implement your own PassportJS auth strategies as it is stated in the docs as well, but it doesnt seem that difficult looking at PassportJS documentation to do so

  • Bakry
    2 weeks ago

    yea it isn't that hard to make but the thing is



    idk how to make it work with payload and payload admin

  • jmikrut
    Payload Team
    2 weeks ago

    you'd just inject your own components into the login screen and make sure that your middleware properly authenticates a user via an HTTP-only cookie. If authenticated, you add the user to the

    req.user

    and then you're golden!

  • Bakry
    2 weeks ago

    so if i make a token using jwt.sign



    then set it in a cookie using setTokenCookie



    and save my req.user as the current user

  • jmikrut
    Payload Team
    2 weeks ago

    yep



    that's basically all that Passport does really

  • Bakry
    2 weeks ago

    the payload middleware authenticates my jwt automatically ?

  • jmikrut
    Payload Team
    2 weeks ago

    it's just middleware that looks out for a cookie or a JWT header, and then decodes the JWT, and sets it to

    req.user


    No, if you are using a custom JWT, then Payload will not know to use it. It will be up to you to do that

  • Bakry
    2 weeks ago

    what if i hook it up with ${payload.config.cookiePrefix}



    as the token name

  • jmikrut
    Payload Team
    2 weeks ago

    you will still need to make sure you use the same encryption that the passport-local-mongoose package uses



    but it could be done

  • Bakry
    2 weeks ago

    hmm can you elaborate more



    yours truly is new to nodejs



    aight i got some ideas i will try to implement and let you know if i run into any problems



    I copied the strategy from the official payload repo



    and in /login i made my own jwt using payload.secret



    and set the cookie with payload.config.cookiePrefix-token



    and set the req.user to the data i got



    and its working somehow lmao

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More