Return a supabase row from the users table when the 'authenticated user' 'user id' is provided

Custom Code

Hi all,

Having fun with Flutterflow and supabase. I would like to create a function or custom action that will receive the 'authenticated user' 'user id' as a parameter which then looks for that particular user in a table called users within supabase and then returns the supabase row with that users data.

I keep getting an error when trying to return the value as a row. As I am still learning flutter, I have hit a big of a road block. I am guessing I need another class? Any help greatly appreciated? Thank you

Code below:

// Automatic FlutterFlow imports
import '/backend/supabase/supabase.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:supabase_flutter/supabase_flutter.dart';

Future<UsersRow?> returnUserRowFromAuthenticatedUser(String userUUID) async {
  // return a supabase row from the users table when the authenticated user reference is provided
// Initialize Supabase client
  await Supabase.initialize(
    url: '',
    anonKey:
        ',
  );
  final supabase = Supabase.instance.client;

// Query the users table for the authenticated user reference
  final response = await supabase
      .from('users')
      .select('id')
      .eq('user_uuid', userUUID)
      .execute();

// Check if the query was successful
  if (response.error != null) {
    throw response.error!;
  }
  //return response;
}
What have you tried so far?

Looked at lots of articles in the community and other locations like reddit but no one seems to have come across this issue. Obviously to achieve what I am doing using firebase would be a lot easier so a lot of the challenges are due to trying to do similar easy tasks in firebase but with supabase!

Did you check FlutterFlow's Documentation for this topic?
Yes
2
5 replies