Is there a way to check if an email has already be...
# javascript
t
Is there a way to check if an email has already been registered with?
g
There is if you write a Postgres function to check that with an rpc call (assuming email is only in auth.users). If you have email in a profiles table then a select would work. Problem is you have no security on these if a signed out user can use them and so anyone could probe your database for valid emails... What are you planning to use the check for?
d
Is there a way to see if username and password match a user in auth.tables?
g
@User Yes
d
How? Is the password hashing exposed an exposed method I could use?
g
hang in there trying to find a thread I was in on it.
Can't find the discussion but this is the code I have in a function to verify a user by uuid and password against stored password
Copy code
SELECT id INTO _uid
  FROM auth.users
WHERE id = auth.uid()
  AND encrypted_password =
  crypt(current_plain_password::text, auth.users.encrypted_password);
Here was the thread: https://github.com/supabase/supabase/discussions/4042
d
Wow fancy
t
I don't want to have a separate "Sign Up" and "Sign In" button
I want the user to enter their email
Then the app decides whether they need to be signed in or signed up
It's my first time using Supabase and PostgresQL, so if you can, please explain like I'm 6
d
You run the query Gary posted. If something returns you then signIn. If nothing returns you sign up
g
So if you really want to check if email exists with a function, this link shows an example: https://discord.com/channels/839993398554656828/870418360934989915/870419785094152213 And you would call it from js with and rpc call like .rpc('email_exists',{user_email:'email'}) But anyone can call that function and probe your system for emails. There is the magic link signin where you just provide an email and the user will get an email link to sign in and it creates an account if the email does not exists. This approach does not use passwords at all and you always sign in with the email security check.
d
Yeah, I don't recommend using that rpc function
t
The link doesn't seem to be working :(
g
Not sure why, I just clicked it and goes to the function...
t
So I just managed to sit down and try the things that you suggested but the rpc call returns this, no matter what I give it
g
Can you show your rpc call and the function name and variables it takes? 404 is saying it could not find your rpc function.
t
it's just this
g
That looks good, did you create the function without error?
t
yep
g
I just did this for function:
Copy code
CREATE OR REPLACE FUNCTION public.email_exists(user_email text)
RETURNS boolean
LANGUAGE sql
SECURITY DEFINER
AS $$
 select exists( select * from auth.users where email = user_email);
$$;
And with your rpc call (email="test@email.com"), it works returning true or false for data.data.
t
well I figured smt out
It's probably not rpc, because everyting returns that same 404 error
my app cannot reach supabase for some reason :/
If I remove the "https://" or "http://" prefix, this happens, but having any of both fails
g
Need to check your url and client key are correctly passed in to the supabase.createClient call.
t
My connector currently looks like this:
It's the same as the tutorial, so I don't know what I messed up
g
console.log the url and key before the call. Also look at the first database call network request and see if url and authorization header look OK.
t
ok, i'll try that too
g
Also it looks like you are using react-native, things work a bit differently with that, but I don't use react anymore let alone react-native. You might search on react-native in the upper search bar or supabase react-native connect issues on web...
Or ask a new question on that specific issue, as I doubt a react-native user will wander thru this thread.
t
ok thanks