Next.js Discord

Discord Forum

Need Help revalidateTag and revalidatePath functions

Unanswered
Cuvier’s Dwarf Caiman posted this in #help-forum
Open in Discord
Avatar
Cuvier’s Dwarf CaimanOP
i use revalidateTag() and revalidatePath() function in server action its working properly in development but not working in production mode.... any one can know. How can i revalidate endpoints useing revalidateTag and revalidatePath

My server action code is like

export async function createCategoryAction(formData: FormData) {
const form = Object.fromEntries(formData)
const { id, categoryId, ...values } = createCategorySchema.parse(form)
let query = Object.create({});
query.create = Object.assign(Object.create({}), { ...values });
query.update = Object.assign(Object.create({}), { ...values });
query.where = Object.assign(Object.create({}), { id: id });
if (categoryId === 'undefined') {
query.update = Object.assign(Object.create({}), { ...values, parentCategory: { disconnect: true } });
} else if (categoryId) {
query.create = Object.assign(Object.create({}), { ...values, parentCategory: { connect: { id: categoryId } } });
query.update = Object.assign(Object.create({}), { ...values, parentCategory: { connect: { id: categoryId } } });
}
try {
await prisma.categories.upsert(query)
revalidateTag("parent-categories")
console.log("Create Or Updated Successfully 👍")
} catch (e) {
console.log("Something went wrong when Creating Or Updating with this error 👎")
console.log(e)
}
}

0 Replies