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!
Should be attached to the res, as per this file
https://github.com/payloadcms/payload/blob/master/src/auth/operations/login.tsThank 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!
do you have auth.cookies.domains configured by chance? (on your auth collection config)
Yes,
auth.cookies.domain: 'localhost:8080'
and that is you CMS domain?
For my development environment, yes.
curious if the same thing happens when you remove that (I believe it will act the same)
You are right, removing
auth.cookies.domain
makes it act as before
Is the code at
https://payloadcms.com/docs/authentication/operations#loginmeant 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!
That is great, thank you for following up
Also, to anyone who is wondering how to implement the Payload Auth Middleware, follow this code
https://discord.com/channels/967097582721572934/1070942828009627698/1071720017068036106Star
Discord
online
Get dedicated engineering support directly from the Payload team..