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

**URL:** https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095
**Category:** How do I?
**Created:** [June 17, 2023, 12:43pm UTC](https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095 "2023-06-17T12:43:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)
#### Post date: [June 17, 2023, 12:43pm UTC](https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095/1 "2023-06-17T12:43:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jaredgibb](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@jaredgibb](https://community.weweb.io/u/jaredgibb)
#### Post date: [June 17, 2023, 1:10pm UTC](https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095/2 "2023-06-17T13:10:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)
#### Post date: [June 17, 2023, 1:22pm UTC](https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095/3 "2023-06-17T13:22:31Z")

</div>

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. 🙂

---

<div class="post-metadata">

### Author: ![jaredgibb](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@jaredgibb](https://community.weweb.io/u/jaredgibb)
#### Post date: [June 17, 2023, 1:48pm UTC](https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095/4 "2023-06-17T13:48:59Z")

</div>

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

> <https://github.com/supabase/gotrue-js/issues/513#issuecomment-1284379733>
>
> \# Bug report
> auth.signup not return error on duplicate email but return user ob…ject.
> 
> \## Describe the bug
> Hello everyone.
> A week ago, all was ok but today, if i try to sign up with an email already registred, i have no error.
> Instead, I receive an user object as if I had created my account (It does not edit account already registred).
> I tryed to sign up with differents passwords, clear cache, different browser, restart server and i have the same result.
> (auth.sign works. I receive user and session with valid credentials and i receive error with invalid)
> .
> \*\*Anyone knows the solution?\*\*
> 
> \`\`\`
> try {
> await supabase.auth.signOut();
> const {user, session, error} = await supabase.auth.signUp({email, password});
> console.log(user, session, error); // return object, null, null
> } catch (e) {
> console.log(e)
> }
> \`\`\`
> 
> \## Expected behavior
> 
> A week ago, I had an error message thanking me for signing up etc. 
> 
> \## System information
> 
> \- OS: Windows 10
> \- Browser: Tested on Chrome, Firefox, Edge
> \- Version of supabase-js: 1.25.2
> \- Version of Node.js: 14.16.0

---

<div class="post-metadata">

### Author: ![tomlagom](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@tomlagom](https://community.weweb.io/u/tomlagom)
#### Post date: [June 19, 2023, 1:40pm UTC](https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095/5 "2023-06-19T13:40:00Z")

</div>

I wrote a pg function

```auto
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](https://supabase.com/docs/guides/auth/managing-user-data)

> 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.

---

<div class="post-metadata">

### Author: ![tomlagom](https://avatars.discourse-cdn.com/v4/letter/t/3be4f8/32.png) [@tomlagom](https://community.weweb.io/u/tomlagom)
#### Post date: [June 19, 2023, 1:41pm UTC](https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095/6 "2023-06-19T13:41:25Z")

</div>

Here if you need help to build the trigger

> **[Creating User Profiles on Sign-Up in Supabase](https://dev.to/sruhleder/creating-user-profiles-on-sign-up-in-supabase-5037)**
>
> Supabase stores authentication-related information (unique ID, email, password, etc.) in the...

---

<div class="post-metadata">

### Author: ![Jamier693](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@Jamier693](https://community.weweb.io/u/Jamier693)
#### Post date: [April 1, 2025, 5:39pm UTC](https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095/7 "2025-04-01T17:39:10Z")

</div>

Hi all - since this post was back in 2023, I’m wondering if a simpler solution exists for this now?

I want to ensure that users can’t sign up if the email already exists, and then provide them with an error message that redirects them to log in.

Thanks!

---

<div class="post-metadata">

### Author: ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)
#### Post date: [April 1, 2025, 5:50pm UTC](https://community.weweb.io/t/supabase-check-if-user-exists-before-signing-up-or-if-exists-log-in/3095/8 "2025-04-01T17:50:18Z")

</div>

Hi, you still need to do it on the Supabase’s side.
