Not getting user exists error when creating user whose email is already there.

hey guys I am getting an strange issue, even when user is registered and am trying to create a new user with the same email, it does give response of user objetc but dont get new user with the new user id in the db. how this is happening, it should give throw user exists error.
export async function createUser(userInputs: CreateUserInputs) {
// check if the passoword and confirm password match
if (userInputs.password !== userInputs.confirmPassword) {
return { success: false, error: true, message: "Passwords do not match" };
}

const supabase = await createClient();
const { data: userData, error } = await supabase.auth.signUp({
email: userInputs.email as string,
password: userInputs.password as string,
options: {
data: {
"persona": "CLUB_ADMIN",
"onboarding_done": false,
"onboarding_status": "NOT_STARTED" as OnboardingStatusType,
"stripe_connect_account_id": "",
"clubId": "",
"name": "",
"players": [],
"teams": [],
},
},
});
if (error) {
console.log("Error creating user:", error);
return {
success: false,
error: true,
message: `User creation failed: ${error.message}`,
};
}
return {
success: true,
error: false,
message:
"User created successfully, please check your email for verification",
user: userData.user,
};
export async function createUser(userInputs: CreateUserInputs) {
// check if the passoword and confirm password match
if (userInputs.password !== userInputs.confirmPassword) {
return { success: false, error: true, message: "Passwords do not match" };
}

const supabase = await createClient();
const { data: userData, error } = await supabase.auth.signUp({
email: userInputs.email as string,
password: userInputs.password as string,
options: {
data: {
"persona": "CLUB_ADMIN",
"onboarding_done": false,
"onboarding_status": "NOT_STARTED" as OnboardingStatusType,
"stripe_connect_account_id": "",
"clubId": "",
"name": "",
"players": [],
"teams": [],
},
},
});
if (error) {
console.log("Error creating user:", error);
return {
success: false,
error: true,
message: `User creation failed: ${error.message}`,
};
}
return {
success: true,
error: false,
message:
"User created successfully, please check your email for verification",
user: userData.user,
};
this is my server actions code creating user.
3 Replies
garyaustin
garyaustin2d ago
Supabase does not error if the email exists for security reasons. https://supabase.com/docs/reference/javascript/auth-signup Details there. If you are not using phone auth there is a way described to trick it to send errors using phone auth settings (even if using email).
nehatkhan
nehatkhanOP22h ago
I am using phone auth also, any why to check user by email ?
garyaustin
garyaustin22h ago
You would have to create a Postgres security definer function that takes in an email address and selects from auth.users to see if it is there and returns true or false. Unless you have a profile table with email in it that you can select from the API. Then you call that with rpc call. Of course anyone could see if a user is using your app at that point, which is what Supabase is trying to avoid.

Did you find this page helpful?