Next.js Discord

Discord Forum

Trouble using server action on client component

Unanswered
vsw posted this in #help-forum
Open in Discord
Avatar
vswOP
I have a standard logout server action that I want to use onclick, how can I do this client-side?

4 Replies

Avatar
vswOP
NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.


Error source:

"use client";

...

<DropdownMenuItem
  onClick={async () => {
    await logout();
    router.push("/");
  }}
>
  <LogOut />
  Log out
</DropdownMenuItem>


Logout server action:

export async function logout() {
  const supabase = await createClient();

  await supabase.auth.signOut();

  revalidatePath("/", "layout");
}
fixes