Question about revalidating tag in server actions
Answered
Hovawart posted this in #help-forum
HovawartOP
Is it safe to do something like this:
Do server actions work like an api routes, where anyone to call them, so anyone would be able to revalidate any tag they want?
"use server";
import { revalidateTag } from "next/cache";
export async function revalidate(tag) {
revalidateTag(tag);
}Do server actions work like an api routes, where anyone to call them, so anyone would be able to revalidate any tag they want?
Answered by joulev
Server actions are basically POST requests behind the scenes, almost exactly like API routes. Anyone can call them yes, so if you don’t want that you need to add additional layers of authentication and authorisation.
1 Reply
@Hovawart Is it safe to do something like this:
js
"use server";
import { revalidateTag } from "next/cache";
export async function revalidate(tag) {
revalidateTag(tag);
}
Do server actions work like an api routes, where anyone to call them, so anyone would be able to revalidate any tag they want?
Server actions are basically POST requests behind the scenes, almost exactly like API routes. Anyone can call them yes, so if you don’t want that you need to add additional layers of authentication and authorisation.
Answer