hello, I've been trying to extract user info from...
# flutter
l
hello, I've been trying to extract user info from the database, and always getting back null result. can anyone take a look
Copy code
dart
class SupabaseConnection {
  final _client = Supabase.instance.client;

  Future supabaseQuery() async {
    final selectResponse = await _client
        .from('users')
        .select()
        // .order('name', ascending: true)
        .eq('email', 'myemail@gmail.com')
        .single()
        .execute();
    if (selectResponse.error == null) {
      print('response.data: ${selectResponse.data}');
    }

    print(selectResponse.data);

  }
}
with the following place in the main.dart
Copy code
dart
  Supabase.initialize(
      url: kSupabaseUrl,
      anonKey: kSupabaseKey,
      // authCallbackUrlHostname: 'login-callback', // optional
      debug: true // optional //todo: check if it should be removed once live
      );
k
is users a table you created or is it the default one?
l
default one
k
I dont believe you can access it directly
you will have to duplicate that table to a public table
l
it worked with supabase-dart package, when I switched to supabase-flutter, it didn't work
okay, I'll try
k
im curious how did it work before? because i'm really sure nobody could access supabase auth (users) table
unless if you create a procedure function with security identifier.
been there.
l
btw, using the sign-up , sends the info to the default table, while 'Profiles' table is left empty
maybe i'm mistaken
k
if you only want to check if email exists then you can do that using a procedure function
something like
Copy code
CREATE OR REPLACE FUNCTION public.email_exists(user_email text)
 RETURNS boolean
 LANGUAGE sql
 SECURITY DEFINER
AS $$
 EXISTS (select * from auth.users where email = user_email); 
$$;
keep in mind this could result in some security issues.
l
yes, it worked with 'Countries' table
k
yeah, thats a public table. any table you are creating can be accessed via the posgrest api, however there is some roles on the ones supabase creates such as users table.
you could easily duplicate that table using postgres triggers, once something is inserted into that table, then copy its data to the new table you call also users or profiles etc.
l
okay, I will try that. btw one small question, for adding more user info, is it a problem to create a stored procedure to insert such info into 'users' table ?
k
something like
Copy code
create trigger user_Created
after
insert
  on auth.users FOR EACH ROW EXECUTE PROCEDURE on_user_created();
then
on_user_created
can copy the data.
u mean the public or supabase private users table?
l
private*
k
its possible, you could add data to app metadata or user metadata.
i wouldn't recommend doing this tho 🙂
please create your own table and do what you like with it
l
okay, great.
thanks for your help ❤️
b
security issues if called from the client right? from the server everything should be fine