-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Bug report
Describe the bug
Hi.
I am having an issue with the FileList function failing to find any files, while used against an endpoint checking header contents.
To Reproduce
In Supabase
I have this function added to my schema, which checks data we put into it, against the tables. You can create it like this.
CREATE OR REPLACE FUNCTION public.is_allowed_apikey(apikey text, tier text)
RETURNS boolean
LANGUAGE plpgsql
SECURITY DEFINER
AS $function$
Begin
RETURN (SELECT EXISTS (SELECT 1
FROM apikeys
WHERE key=apikey
AND tiers=tier));
End;
$function$
Then, on my bucket (which doesn't matter if is public or private), I have this RLS:
((bucket_id = 'BUCKET'::text) AND public.is_allowed_apikey(((current_setting('request.headers'::text, true))::json ->> 'apikey'::text), 'TIER_NAME'::text))
What's important about this, is. It checks if the key is in database & if the "tier" column has "TIER_NAME" in it.
In application
Now. In my C#, supabase lib using code, I have this:
public void InitializeSupabase(string privateKey)
{
this.privateKey = privateKey;
var options = new Supabase.SupabaseOptions
{
//AutoConnectRealtime = true,
Headers = new Dictionary<string, string>(){
{ "apikey", privateKey } // Important part. Set apikey in header, to get Premium content
}
};
Supabase.Client _supabase = new Supabase.Client(publicURL, publicKey, options);
try
{
Task.Run(() => _supabase.InitializeAsync()).Wait();
//if (supabase.Realtime.Socket.IsConnected) supabase.Realtime.Disconnect();
supabase = _supabase;
status = Status.authorized;
}
catch
{
// Throw a box for the user, stating that their code was wrong
}
}
public void getData() {
foreach (Supabase.Storage.Bucket _bucket in Task.Run(() => supabase.Storage.ListBuckets()).GetAwaiter().GetResult())
{
foreach (Supabase.Storage.FileObject _file in Task.Run(() => supabase.Storage.From(_bucket.Id).List()).GetAwaiter().GetResult())
{
_file.BucketId = _bucket.Id; // This is really stupid. Why isn't the bucketId filled on fetch?
recursiveSupabaseFileListing(public_files, _file, "");
}
}
}
This stuff finds all the buckets correctly. But then the bucket with verification is empty?
The Storage
object inside supabase
, seems to have the "Headers: apikey = rstanasto" added to it correctly, but still, doesn't report any files in the directory.
It is not a problem with the recursiveListing function, because the supabase.Storage.From(_bucket.Id).List()
function returns empty array in the first place.
Expected behavior
Here is C# code that queries the endpoint correctly and gets the data
var client = new HttpClient();
var request = new HttpRequestMessage();
request.RequestUri = new Uri("https://{MY_SERVER}.supabase.co/storage/v1/object/list/Premium");
request.Method = HttpMethod.Post;
request.Headers.Add("Accept", "*/*");
request.Headers.Add("apikey", "{SPECIAL_KEY}");
request.Headers.Add("Authorization", "Bearer {PUBLIC_KEY}");
var bodyString = "{\"prefix\":\"special_directory/\",\"HttpUploadTimeout\":\"-00:00:00.0010000\",\"HttpDownloadTimeout\":\"-00:00:00.0010000\",\"HttpRequestTimeout\":\"00:01:40\"}";
var content = new StringContent(bodyString, Encoding.UTF8, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
this gets a response containing files, e.g.
[
{
"name": "aarchive.zip",
"id": "ad8f90e8-377a-4ea7-980b-5b36358e24b3",
"updated_at": "2024-09-01T17:35:52.113Z",
"created_at": "2024-09-01T17:35:27.875Z",
"last_accessed_at": "2024-09-01T17:35:27.875Z",
"metadata": {
"eTag": "\"ffc878cd7cf4375e0fd043d76ebe8595\"",
"size": 1264627,
"mimetype": "application/zip",
"cacheControl": "max-age=3600",
"lastModified": "2024-09-01T17:35:52.000Z",
"contentLength": 1264627,
"httpStatusCode": 200
}
}
]
Screenshots
NULL
System information
- OS: Windows 10 LTSC, Build 19041.vb_release.191206-1406
- Browser: Edge [Lord]
- Version of supabase-csharp: 1.1.1
- Version of supabase-csharp-storage: 2.0.2
- Version of Visual Studio: 2022 17.12.0 Preview 1.0
- Version of .NET Framework: 9.0.100-preview.7.24407.12
Additional context
It has been two days of this stuff not working and I am too tired to debug this anymore...
P.S.
I encapsulate all my supabase calls in Task.Run(() => supabase.DOSOMETHING()).GetAwaiter().GetResult()
, because WinForm UI gets broken when ran inside an asynchronous context (async main).
So... I either have async context & clean supabase calls, or I have working UI. The choice is simple.