0

I'm working on a sign-up feature using Supabase and I want to provide feedback to the user if they try to sign up with an email that already exists in the system. I found a relevant GitHub discussion thread and opted for the solution provided by PrabhdeepSingh.

Here's my code:

const handleSignUp = async () => {
  const response = await supabase.auth.signUp({
    email,
    password,
    options: {
      emailRedirectTo: `${location.origin}/auth/callback`,
    },
  });

  console.log("Sign-up response:", JSON.stringify(response, null, 2));

  if (response.data && response.data.user) {
    if (response.data.user.identities && response.data.user.identities?.length > 0) {
      console.log("Sign-up successful!");
    } else {
      console.log("Email address is already taken.");

      const resendResponse = await supabase.auth.resend({ email, type: "signup" });
      console.log("Resend response:", JSON.stringify(resendResponse, null, 2));

      if (resendResponse.error) {
        console.error("An error occurred while resending the email:", resendResponse.error.message);
      } else {
        console.log("Confirmation email resent successfully!");
      }
    }
  } else {
    console.error("An error occurred during sign-up:", response.error?.message);
  }

  router.refresh();
};

Logs:

Here are the logs I received (email and ID are censored for privacy):

Sign-up response: {
  "data": {
    "user": {
      "id": "[CENSORED]",
      "aud": "authenticated",
      "role": "authenticated",
      "email": "[CENSORED]",
      ...
      "identities": [],
      ...
    },
    "session": null
  },
  "error": null
}
Identities array: []
Email address is already taken.
Resend response: {
  "data": {
    "user": null,
    "session": null
  },
  "error": null
}
Confirmation email resent successfully!

Questions:

  1. Is this approach correct for handling sign-ups where the email already exists?
  2. Despite the console log stating "Confirmation email resent successfully!", I'm not receiving any confirmation emails. Why might this be happening?

Any insights or suggestions would be greatly appreciated. Thank you!

Vladimirzb
  • 87
  • 6

1 Answers1

1

Maybe you are not getting any email, since you can send up to 3 emails free per month.