Payload Auth Login not setting HTTP-only cookie

default discord avatar
Luciano
8 months ago
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!

  • default discord avatar
    Jarrod
    8 months ago
  • default discord avatar
    Luciano
    7 months ago

    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!

  • default discord avatar
    Jarrod
    7 months ago

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

  • default discord avatar
    Luciano
    7 months ago

    Yes,

    auth.cookies.domain: 'localhost:8080'
  • default discord avatar
    Jarrod
    7 months ago

    and that is you CMS domain?

  • default discord avatar
    Luciano
    7 months ago

    For my development environment, yes.

  • default discord avatar
    Jarrod
    7 months ago

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

  • default discord avatar
    Luciano
    7 months ago

    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!

  • default discord avatar
    Jarrod
    7 months ago

    That is great, thank you for following up

  • default discord avatar
    Luciano
    7 months ago

    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.