Payload Auth Login not setting HTTP-only cookie

default discord avatar
Luciano
last month
14

Hello everyone,



Trust you are well & having a great day!



What do I need to do to allow this code to set a cookie?



result = await payload.login({ collection: 'accounts', data: { email: email, password: password, }, });

Thank you!

  • discord user avatar
    Jarrod
    Payload Team
    last month
  • default discord avatar
    Luciano
    last month

    Thank you for sending me this file, you are correct the code does show that, however no cookie is being attached to the res on my end!

  • discord user avatar
    Jarrod
    Payload Team
    last month

    do you have auth.cookies.domains configured by chance? (on your auth collection config)

  • default discord avatar
    Luciano
    last month

    Yes,

    auth.cookies.domain: 'localhost:8080'
  • discord user avatar
    Jarrod
    Payload Team
    last month

    and that is you CMS domain?

  • default discord avatar
    Luciano
    last month

    For my development environment, yes.

  • discord user avatar
    Jarrod
    Payload Team
    last month

    curious if the same thing happens when you remove that (I believe it will act the same)

  • default discord avatar
    Luciano
    last month

    You are right, removing

    auth.cookies.domain

    makes it act as before



    Is the code at

    https://payloadcms.com/docs/authentication/operations#login

    meant to be implemented on the front end? Because mine is run on the backend



    After setting the cookie manually & visiting

    http://localhost:8080/api/accounts/me

    , that works. The Payload Auth Middleware however is not working when checking

    req.user


    @Jarrod just want to confirm that Auth Login is now setting a cookie once I added payload.login

    res: res,

    & removed

    auth.cookies.domain


    Thank you for your help!

  • discord user avatar
    Jarrod
    Payload Team
    last month

    That is great, thank you for following up

  • default discord avatar
    Luciano
    last month

    Also, to anyone who is wondering how to implement the Payload Auth Middleware, follow this code

    https://discord.com/channels/967097582721572934/1070942828009627698/1071720017068036106
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.