Server Action Architecture question
Unanswered
English Angora posted this in #help-forum
English AngoraOP
Heya, how do yall handle calling server actions from different routes:
Since, you can't revalidatePath in the client component;
Say I want to redirect from pageA -> anotherpageA and from pageB -> anotherpageB with a single server action like the one provided.
export const getUsers = async () => {
revalidatePath("/");
return db.select().from(users);
};Since, you can't revalidatePath in the client component;
Say I want to redirect from pageA -> anotherpageA and from pageB -> anotherpageB with a single server action like the one provided.
23 Replies
do you mind elaborting a bit more
if you want to redirect someone via a server action
@linesofcode do you mind elaborting a bit more
English AngoraOP
yeah, sure
I want to revalidate the current path
you could pass that path via the args to the server action
@linesofcode you could pass that path via the args to the server action
English AngoraOP
yeah but I don't want to pass getUsers("/pathhere"), can't It be done automatically?
write a little wrapper
which pulls the path from the router
and then passes it to the server action automatically
English AngoraOP
but thats doing the same thing
you could try pulling it from the headers
English AngoraOP
something like:
export const getUser = async (id: number) => {
revalidatePath(headers().get("referer"));
return db.select().from(users).where(eq(users.id, id));
};@linesofcode you could try pulling it from the headers
English AngoraOP
oh yeah i tried but it doesn't work, the headers are empty
English AngoraOP
ðŸ‘
English AngoraOP
sec
request for server action has a referer token but I can't access it 🤔
also the middleware solution isn't working
nvm, didn't found solution but sick of next lol