clerk / javascript

Official Javascript repository for Clerk authentication
https://clerk.com
MIT License
1.04k stars 235 forks source link

Error when trying to upload file to Supabase: `invalid input syntax for type uuid` #1056

Closed magnusrodseth closed 1 year ago

magnusrodseth commented 1 year ago

I have a Next.js application using Supabase for data and file storage, and Clerk for user storage and authentication. Because users are stored with an ID like user_abcdefghijkl, and not a UUId like 123e4567-e89b-12d3-a456-426614174000, I get the following error when trying to upload a file to Supabase:

{
  "statusCode":"500",
  "error":"Database Error",
  "message":"invalid input syntax for type uuid: \"user_abcdefghijkl\""
}

This is the error that I console.log when calling the following:

  await supabase.storage.from(BUCKET_ID).upload(path, file, {
    cacheControl: "3600",
    contentType: "application/pdf",
    upsert: true,
  });

All other data can be successfully written to and read from the database.

It seems to me like the call to .upload(...) implicitly checks the user ID of the currently logged-in user, and throws because the user ID is not a UUID.

Note that the userId is stored as TEXT in the database, due to the way Clerk generated IDs.

Currently, during development, I allow all users to select, insert, update and delete. Hence, I don't think the error stems from a policy that's too restrictive.

How can I solve this issue and allow users to upload files?

dimkl commented 1 year ago

Hello @magnusrodseth, based on your description and since the error is raised from the supabase.storage.from(BUCKET_ID).upload(...) i think that this is not related to the ClerkJS codebase and you probably need to open the ticket to Supabase.

I cannot think of a way that this issue could be fixed from the Clerk side since it's a DatabaseError in Supabase for storing files. If the Supabase team identifies something related to our codebase, please re-open this ticket and let me know how i can help you.