I creating back-end program using Fastify, and deployed it on Vercel and got this problem:
Cookie “__vercel_live_token” has been rejected because it is in a cross-site context and its “SameSite” is “Lax” or “Strict”.
But i setup cookies in my project like this
import { errorHandler } from '@/middlewares/error-handler';
import Fastify from 'fastify';
import cors from '@fastify/cors'
import cookie from '@fastify/cookie'
import router from '@/router';
const fastify = Fastify({
logger: true,
});
fastify.register(cors)
fastify.register(cookie, {
parseOptions: {
httpOnly: true,
sameSite: 'none',
secure: true
}
})
fastify.setErrorHandler((error, request, reply) => {
errorHandler(error, request, reply)
})
fastify.register(router, {prefix: '/api'})
try {
await fastify.listen({ port: 5000 });
console.log(`Server listening at http://localhost:5000`);
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
So why i still get this error?
When you set a cookie using:
parseOptions: {
httpOnly: true,
sameSite: 'none',
secure: true
Then you need to use https://localhost:5000 and not http://localhost:5000.