Cannot revalidate path in route handler
Unanswered
Common paper wasp posted this in #help-forum
Common paper waspOP
I am creating a simple app with following stack: nextjs 14 (app router), prisma, next-auth v5.
1. So I have a page
Render a list just calling a function to get all list like that
2.
I would love to use server actions to create a list but I want to show toast (sonner lib) to show that the list was created. So I decided to go with route handlers for create/update methods. For example this is my api route to create a list:
With that, I cannot revalidate data on
1. So I have a page
/dashboard/lists to show all lists.Render a list just calling a function to get all list like that
export async function ListPage() {
const lists = await getLists();
...
}getLists.tsimport { cache } from "react";
export const getLists = cache(() => {
return prisma.list.findMany({ orderBy: { createdAt: "desc" } });
});2.
/dashboard/lists/create with a form to create a list.I would love to use server actions to create a list but I want to show toast (sonner lib) to show that the list was created. So I decided to go with route handlers for create/update methods. For example this is my api route to create a list:
export async function POST(request: Request) {
const session = await auth();
if (session?.user) {
const payload = await request.json();
const response = await prisma.list.create({
data: {
...payload,
owner: { connect: { id: session.user.id } },
},
});
// this doesn't work
revalidatePath("/dashboard/lists");
return Response.json({ list: response });
}
return Response.json({ message: "Not authenticated" }, { status: 401 });
}With that, I cannot revalidate data on
/dashboard/lists. Am I doing something wrong? It's not possible by design and should I switch all my crud to route handlers on the client side and use something like tanstack? 😦