Supabase - Check if user exists before Signing up? Or if exists log in

Hello,

I’m trying to hack around this, but I haven’t found a way to check whether the user is registered already, before registering him again, this way, users now can register themselves till infinity. I’d like to check if user exists already and either log them - with the credentials, or redirect them to login.

Is there a way to maybe check if user exists in Supabase?

Thanks

if supabase lets you ‘reregister’ users till the universe ends, you could think about setting up a precondition, perhaps using a simple edgeFunction that checks if there is a user with that email

so the logic would be

user fills out registration form
weweb calls out to a supabse function
the supabase function checks for the existence of a user with that email
if they dont exist, sign them up
if they exist, do nothing
return a message to weweb that the function ran succesfully
show the user a message that instructs them to check their inbox for an email. this way users can’t ‘check to see’ if a user has already signed up for your site AND doesnt reregister them.

Yeah, this is a valid option, but I’m wondering whether either the Supabase Auth implementation or WeWeb hasn’t a quicker solution for this. But yeah, if there won’t be any other option, I’ll code my own logic for this. :slight_smile:

1 Like

It’s an annoying supabase thing. You need to set this up yourself

I wrote a pg function

DECLARE
  user_id uuid;
BEGIN
  SELECT id
  INTO user_id
  FROM users
  WHERE users.email = validate_user_exists.email;

  RETURN user_id;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    RETURN NULL;
END;

Note that I’m querying public scheme. Managing User Data | Supabase Docs

For security purposes, the auth schema is not exposed on the auto-generated API.

So I also created a trigger that POST a user every time a new user is sign up.

2 Likes

Here if you need help to build the trigger

1 Like