[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live) [Help](/c/help/9) # I can set the cookie when the app is running on localhost but when i deploy it on vercel the cookie is not set #mern stack 282 views · 2 likes · 9 posts Coderpawan (@coderpawan) · 2024-07-20 · ♥ 1 <!-- Be sure to include all detail needed to let others see the same problem --> Below is the code for the generateToken function which gets called when the user tries to login import jwt from "jsonwebtoken"; const generateToken = (res, userId) => { const token = jwt.sign({ userId }, process.env.JWT_SECRET, { expiresIn: "30d", }); // Set JWT as an HTTP-Only Cookie res.cookie("jwt", token, { expires: new Date( [Date.now](https://Date.now)() + 30 * 24 * 60 * 60 * 1000 ), httpOnly: true, secure:true, sameSite: "none" }); return token; }; export default generateToken; Login/Logout Controller function const loginUser = asyncHandler(async (req, res) => { const { email, password } = req.body; const existingUser = await User.findOne({ email }); if (existingUser) { const isPasswordValid = await [bcrypt.compare](https://bcrypt.compare)( password, existingUser.password ); if (isPasswordValid) { createToken(res, existingUser._id); res.status(201).json({ _id: existingUser._id, username: existingUser.username, email: [existingUser.email](https://existingUser.email), isAdmin: existingUser.isAdmin, }); return; } } }); const logoutCurrentUser = asyncHandler(async (req, res) => { res.cookie("jwt", "", { httyOnly: true, expires: new Date(0), }); res.status(200).json({ message: "Logged out successfully" }); }); Please help me out with this error Github Repo: https://github.com/coderpawan/E-commerce 3den (@3den) · 2024-07-22 I am having the same problem since Friday. I have a app that logs in using supabase auth, everything was working fine before and still works fine on localhost. Now on every new deploy the login works but the cookies are not persisted so that any navigation will redirect back to the login page again. I have reverted prod to the previous deploy, which still works. But if I try to deploy the same commit it does not work. I think something changed internally in vercel to mess things up. Coderpawan (@coderpawan) · 2024-07-23 But if the things have internally changed it would mishap the whole thing because we can't let users to pay or checkout before authorisation. How to handle this I cant think anymore 3den (@3den) · 2024-07-23 I was debugging this all day, seems like vercel injected some middleware the messes up with the cookies. Its the first time i need their support but no one replies and they replaced chat support with a useless gpt. 3den (@3den) · 2024-07-23 There is an other ticket about the exact same problem => https://community.vercel.com/t/next-auth-api-route-throwing-error-failed-to-collect-page-data-for-api-auth-nextauth-only-on-production/195 Planify La (@planify-la) · 2024-07-23 · ♥ 1 We are experiencing this problem. We are not able to use server actions in Nextjs and Supabase. Pauline P. Narvas (@pawlean) · 2024-07-24 > The problem on my end was coz the <Link> started all prefetching including prefetching the logout button, that it was the same logic since forever but vercel started default prefetch to true. Looks like you're good now, @3den! :smile: Pauline P. Narvas (@pawlean) · 2024-07-24 Let's keep your conversation in one place: [Next auth api route throwing Error: Failed to collect page data for /api/auth/[...nextauth] only on production ](https://community.vercel.com/t/next-auth-api-route-throwing-error-failed-to-collect-page-data-for-api-auth-nextauth-only-on-production/195) :slight_smile: Pauline P. Narvas (@pawlean) · 2024-07-24 Hi @coderpawan! Are you still experiencing this issue?