On Demand Revalidattion Error in Secret Key Verification - Hygraph and Next JS

25 Views Asked by At

This is my next js code filename is /api/revalidate.ts i keep getting this error {message: "Invalid"}

i use secret key in my .env and in webhook of hygraph but still getting the error i also used headers secret instead of secret key, and added my secret in vercel dont know whenever i visit deployed link did not get new post only on local server i found them !!!

enter image description here

// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
import path from "path"


export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {

    // checking for the secret
    if(req.query.secret !== process.env.SECRET){
        return res.status(401).json({message: "Invalid"})
    }

    try {
       

        await res.revalidate('/')
        await res.revalidate(`/blog/${req.body.data.content.slug}`)

        return res.json({revalidated: true})

    } catch (error) {
        return res.status(500).send({
            error: 'Error'
        })
    }

}

write the correct code or tell me my mistake what i doing wrong

0

There are 0 best solutions below