Next.js Discord

Discord Forum

What is the cause of the page not refresh after successfully redirect?

Answered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
I have a login form when user successfully signin they will get redirect to "/" page. At the home page, Navbar component is hidden to non-user by default. But even after user successfully loign, and get redirect to "/". The page seem to not refresh (navbar not appear) then if I manually refresh the page then navbar become visible.

Is there any action to do this?

export async function login(formData: FormData) {
  const supabase = createClient();

  const data = {
    email: formData.get("email") as string,
    password: formData.get("password") as string,
  };
  const { error } = await supabase.auth.signInWithPassword(
    data,
  );

  if (error) {
    console.log(error);
    redirect("/error");
  }

  revalidatePath("/", "page");
  redirect("/");
}


this is my login function.

My assumption is that the redirect happen BEFORE data(user) fullfill. Is there any solution to this?
Answered by Sun bear
my solution was do the redirect in the component that called this login function instead.
View full answer

18 Replies

Transvaal lion
@Sun bear Did you ever figure out a solution to this? I'm running into the same issue (with the same use case).
@gin is login ur server action?
Sun bearOP
yes
@Sun bear yes
hmm it should work
@Transvaal lion <@562448610457944126> Did you ever figure out a solution to this? I'm running into the same issue (with the same use case).
Sun bearOP
my solution was do the redirect in the component that called this login function instead.
Answer
did u fix it?
Sun bearOP
using router.push()
i was about to tell u that
Sun bearOP
middleware that wrap around the app might cause weird behaviour and hard to debug
the thread will be resolved
Sun bearOP
ok
can I? can't seem to find an action to do that
@Sun bear can I? can't seem to find an action to do that
Sun bearOP
done
👍