Next.js Discord

Discord Forum

The page isn’t redirecting properly

Unanswered
Samir posted this in #help-forum
Open in Discord
Avatar
SamirOP
My code to fetch user's info
export const getUser = cache(async (): Promise<UserI> => {
  const supabase = createServerComponentClient<Database>({ cookies });

  // gets authenticated data
  const { data } = await supabase.auth.getUser();
  if (data.user !== null) {
    const { data: profile, error: profileE } = await supabase
      .from("users")
      .select("*")
      .eq("user_id", data.user.id)
      .maybeSingle();

    if (
      profile === null ||
      profileE !== null ||
      Object.keys(profile).length === 0
    ) {
      redirect("/login");
    }

    Object.defineProperty(profile, "email", {
      value: data.user.email,
      writable: false,
    });

    return profile as UserI;
  }

  redirect("/login");
});

But somehow it just spams on tunneling site like ngrok, cloudflared

1 Reply

Avatar
SamirOP
Image