Next.js Discord

Discord Forum

Server Action Signout with <Form> and Next.js 15 not redirecting

Unanswered
American Crocodile posted this in #help-forum
Open in Discord
Avatar
American CrocodileOP
Hello, I'm having a problem not being able to redirect a user after logout with my server action.

Here is the code for the server action:

"use server";
import { createClient } from "@/lib/supabase/server";
import { redirect } from "next/navigation";

export async function signOut() {
  const supabase = await createClient();
  await supabase.auth.signOut();
  redirect("/login");
}


Here is the part of the signout form

    <DropdownMenuItem className="w-full flex-1 cursor-pointer text-red-500">
          <Form className="w-full" action={signOut}>
            <button type="submit" className="flex w-full">
              <LogOut className="mr-2 h-4 w-4" />
              <span>Signout</span>
            </button>
          </Form>
        </DropdownMenuItem>


I do a a 303 happening on the server action call, the user is actually logged out but the page stays the current. If I refresh the browser the user is actualy signout and redirect by the middleware.

Any idea what could cause this behaviour?
Image

4 Replies

Avatar
American CrocodileOP
Image
Avatar
I guess it's because you are using next/form??
can you try with native <form />?
Avatar
American CrocodileOP
Same problem 😦