Payload Auth Login not setting HTTP-only cookie

default discord avatar
Lucianolast year
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
    Jarrodlast year
  • default discord avatar
    Lucianolast year

    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
    Jarrodlast year

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

  • default discord avatar
    Lucianolast year

    Yes,

    auth.cookies.domain: 'localhost:8080'
  • default discord avatar
    Jarrodlast year

    and that is you CMS domain?

  • default discord avatar
    Lucianolast year

    For my development environment, yes.

  • default discord avatar
    Jarrodlast year

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

  • default discord avatar
    Lucianolast year

    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
    Jarrodlast year

    That is great, thank you for following up

  • default discord avatar
    Lucianolast year

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

    https://discord.com/channels/967097582721572934/1070942828009627698/1071720017068036106
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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