Documentation can be found below, on the Supabase Developer Documentation and additionally in the Generated API Docs.
- Integration with Supabase.Realtime
- Integration with Postgrest
- Integration with Gotrue
- Integration with Supabase Storage
- Integration with Supabase Edge Functions
- Nuget Release
- Blazor WASM Template using Supabase - Repo / Live demo by @rhuanbarros
- Realtime Example using Supabase Realtime Presence - Repo / Live demo
(Create a PR to list your work here!)
Care has been taken to mirror, as much as possible, the Javascript Supabase API. As this is an unofficial client, there are times where this client lags behind the offical client. If there are missing features, please open an issue or pull request!
- To get started, create a new project in the Supabase Admin Panel.
- Grab your Supabase URL and Supabase Public Key from the Admin Panel (Settings -> API Keys).
- Initialize the client!
Note: supabase-csharp has some APIs that require the service_key rather than the public_key (for instance: the administration of users, bypassing database roles, etc.). If you are using the service_key be sure it is not exposed client side. Additionally, if you need to use both a service account and a public/user account, please do so using a separate client instance for each.
Initializing a barebones client is pretty simple.
var supabase = new Supabase.Client(SUPABASE_URL, SUPABASE_KEY);
await supabase.InitializeAsync();Or, using options:
var options = new SupabaseOptions
{
AutoConnectRealtime = true
};
var supabase = new Supabase.Client(SUPABASE_URL, SUPABASE_KEY, options);
// Calling InitializeAsync will automatically attempt a socket connection if specified in the options.
await supabase.InitializeAsync();As for actually using the client, each service is listed as a property on Supabase.Client. Some services have helpers to make interactions easier. Properties are provided for every client in the event that advanced customization of the client is needed.
Supabase.Postgrest- Is better accessed using
supabase.From<ModelName>()as it provides a wrapper class with some helpful accessors (see below)
- Is better accessed using
Supabase.Realtime- If used for listening to
postgres_changescan be accessed using:supabase.From<ModelName>().On(listenerType, (eventType, data) => {}) - Otherwise, use
Supabase.Realtime.Channel("channel_name")forBroadcastandPresencelisteners.
- If used for listening to
// Get the Auth Client
var auth = supabase.Auth;
// Get the Postgrest Client for a Model
var table = supabase.From<TModel>();
// Invoke an RPC Call
await supabase.Rpc("hello_world", null);
// Invoke a Supabase Function
await supabase.Functions.Invoke("custom_function");
// Get the Storage Client
var storageBucket = supabase.Storage.From("bucket_name");
// Use syntax for broadcast, presence, and postgres_changes
var realtime = supabase.Realtime.Channel("room_1");
// Alternatively, shortcut syntax for postgres_changes
var postgres_changes = supabase.From<TModel>().On(ChannelEventType.All, (type, changes) =>
{
switch (type)
{
case ChannelEventType.Insert:
break;
case ChannelEventType.Update:
break;
case ChannelEventType.Delete:
break;
}
});Notes
- Be aware that many of the supabase features require permissions for proper access from a client. This is especially true for
realtime,postgres, andstorage. If you are having problems getting the client to pull data, verify that you have proper permissions for the logged in user. - Connection to
Supabase.Realtimeis, by default, not enabled automatically, this can be changed in options. - When logging in using the
Supabase.Auth(Gotrue) client, state is managed internally. The currently logged in user's token will be passed to all the Supabase features automatically (via header injection). - Token refresh enabled by default and is handled by a timer on the Gotrue client.
- Client libraries listed above have additional information in their readme files.
Of course, there are options available to customize the client. Which can be found in Supabase.SupabaseOptions.
You can specify a session handler to persist user sessions in your app. For example:
CustomSessionHandler.cs
class CustomSessionHandler : Supabase.Interfaces.ISupabaseSessionHandler
{
public Task<bool> SessionDestroyer()
{
// Destroy Session on Filesystem or in browser storage
throw new NotImplementedException();
}
public Task<bool> SessionPersistor<TSession>(TSession session) where TSession : Session
{
// Persist Session in Filesystem or in browser storage
// JsonConvert.SerializeObject(session) will be helpful here!
throw new NotImplementedException();
}
public Task<TSession> SessionRetriever<TSession>() where TSession : Session
{
// Retrieve Session from Filesystem or from browser storage
// JsonConvert.DeserializeObject<TSession>(value) will be helpful here!
throw new NotImplementedException();
}
}Then initialize using the specified handler:
Main.cs
var options = new SupabaseOptions
{
// ....
SessionHandler = new CustomSessionHandler()
};
var supabase = new Supabase.Client(SUPABASE_URL, SUPABASE_KEY, options);
// Calling InitializeAsync will automatically invoke the SessionHandler to setup the internal session state
await supabase.InitializeAsync();Join the ranks! See a problem? Help fix it!
Made with contrib.rocks.
We are more than happy to have contributions! Please submit a PR.
