Using Supabase in Cloud Code

Hello, I'm trying to deploy cloud code in Unity Editor and I want to use Supabase for this.

So, I added the following line at the top of my script:

const { createClient } = require('@supabase/supabase-js');

However, I'm encountering the following error:

[code]
[CloudCodeAuthoring]: '"/Users/mek/cloud code/Library/PackageCache/com.unity.services.cloudcode@2.5.1/Editor/Authoring/Core/Bundling/Assets~/shim.cjs" "/Users/mek/cloud code/Assets/CloudCode/create_new_player.js"' command exited with 1
STDERR: The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
'@unity-services/cloud-save-1.4' is imported by
UnityEngine.Logger:LogError (string,object)
Unity.Services.CloudCode.Authoring.Editor.Shared.Logging.Logger:LogError (object) (at Library/PackageCache/com.unity.services.cloudcode@2.5.1/Editor/Authoring/Shared/Logging/Logger.Gen.cs:17)
Unity.Services.CloudCode.Authoring.Editor.Logging.Logger:LogError (object) (at Library/PackageCache/com.unity.services.cloudcode@2.5.1/Editor/Authoring/Logging/Logger.cs:10)
Unity.Services.CloudCode.Authoring.Editor.Bundling.EditorScriptBundler/d_5:MoveNext () (at Library/PackageCache/com.unity.services.cloudcode@2.5.1/Editor/Authoring/Bundling/EditorScriptBundler.cs:59)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetException (System.Exception)
Unity.Services.CloudCode.Authoring.Editor.Projects.NodePackageManager/d
22:MoveNext () (at Library/PackageCache/com.unity.services.cloudcode@2.5.1/Editor/Authoring/Projects/NodePackageManager.cs:137)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult (Unity.Services.CloudCode.Authoring.Editor.Projects.ProcessOutput)
Unity.Services.CloudCode.Authoring.Editor.Projects.ProcessRunner/d
0:MoveNext () (at Library/PackageCache/com.unity.services.cloudcode@2.5.1/Editor/Authoring/Projects/ProcessRunner.cs:68)
System.Threading.Tasks.TaskCompletionSource`1:TrySetResult (object)
Unity.Services.CloudCode.Authoring.Editor.Projects.ProcessRunner/<>cDisplayClass3_0:b_0 (object,System.EventArgs) (at Library/PackageCache/com.unity.services.cloudcode@2.5.1/Editor/Authoring/Projects/ProcessRunner.cs:87)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
[/code]

I am not sure how to resolve this issue. Could you please help me make Supabase work in this environment?

9482128--1333549--upload_2023-11-20_15-27-36.png

Hi mek_unity525,

Cloud Code Javascript only provides a small set of libraries, Supabase is not one of those. See here for a list of supported packages in javascript https://docs.unity.com/ugs/en-us/manual/cloud-code/manual/scripts/reference/available-libraries.

You could have a look at the Cloud Code C# modules instead (https://docs.unity.com/ugs/en-us/manual/cloud-code/manual/modules), which allows you to include any package from nuget. You can find the Supabase libraries on nuget here https://www.nuget.org/profiles/supabase.

C# modules in Cloud Code is definitely the more flexible of the two runtimes we provide.

Hope that helps!

1 Like

Hey mek_unity525!

While it is true that from the dashboard you cannot use other libraries, you can make Supabase work by setting up Javascript bundling from the editor workflows: https://docs.unity3d.com/Packages/com.unity.services.cloudcode@2.5/manual/Authoring/javascript_project.html#bundling

Have you set that up? What else do you have in you script? Feel free to PM me for more help :)

1 Like

Hello! I have a question.

I am trying to use Cloud Code with JavaScript.
I’m deploying my Node.js code built in Visual Studio Code using UGS CLI.

In this situation, what I want to do is:

  1. Trigger Cloud Code to store information in Cloud Save when a user signs up (I’ve succeeded in this part).
  2. Additionally, I want to save the information in Supabase as well.

Therefore, I installed the Supabase module in my local Visual Studio Code project using npm install and attempted to deploy it, but I encountered an error.

I also tried using the Unity Editor, but faced the error I mentioned in this question. Now, I am not sure what to do next.

Could you please advise me on whether it is possible to implement the functionality I desire?

I apologize for asking this question without thoroughly reading the documentation.

Hi,

I tried out the setup of supabase in CloudCode JS and it fails as it requires a dependency on websocket.
Websockets afaik are not supported by CloudCode.

Your best alternative is to use C# CloudCode to import the C# library. (Create > CloudCode Module Reference)
Then generate a c# solution (Right-click on the reference in the deployment window > Generate project).

In that project, import the required C# library.

I will continue checking if supabase really requires websockets.

Alternatively, depending on what you need from supabase, you could probably use the Unity alternative.
I will continue looking into this to see if it can be resolved or the messaging can be improved.

1 Like

supabase works fine with the c# library. its a little work because its not official so some things need to be translated. what i do is setup my connection in the Setup function and store a reference to it

That is an Extremely limited list for utility node packages (only lodash). No crypto, no in-app-purchase (which is in your official documentation for Unity IAP for server side validation of purchase receipt).