platforms icon indicating copy to clipboard operation
platforms copied to clipboard

Revalidation doesn't work when hosted on Vercel

Open kul-sudo opened this issue 2 years ago • 1 comments

Hello, everybody!

Well, I have a NextJS project which contains the following code in api/revalidate:

export default async function handler(req, res) {
  if (req.query.secret !== process.env.SECRET_TOKEN) {
    return res.status(401).json({ message: 'Invalid token' })
  }

  try {
    await res.revalidate('/blog/g_pro_wireless')
    return res.json({ revalidated: true })
  } catch (err) {
    return res.status(500).send('Error revalidating')
  }
}

When I do http://my_perfect_website.com/api/revalidate?secret=the_token in the hosted production version, nothing works; however, if I do http://localhost:3000/api/revalidate?secret=the_token after doing yarn run build and yarn run start, everything works. Evidently, the problem appears once I have deployed the app to Vercel. What can I do?

By the way, if I remove the token validation, it merely shows Error validating in the hosted production version, whereas both with the token and without everything works perfectly in the non-hosted production version.

Also, I have a free domain.

kul-sudo avatar Mar 02 '23 17:03 kul-sudo

Also seeing this. I think it is to do with Middleware caching - if I go to the sites (not via subdomain, ie /_sites/test) it works for me

jabza avatar Mar 17 '23 17:03 jabza

Hey! This should be fixed now with the https://github.com/vercel/platforms/pull/221 migration complete since we moved to using revalidateTag inside Server Actions (no need for secret tokens :woohoo:)! Gonna close this for now but LMK if you need to reopen this issue!

steven-tey avatar Jul 10 '23 18:07 steven-tey