• Stars
    star
    452
  • Rank 96,234 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created about 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A C# Client library for Supabase

Documentation can be found below, on the Supabase Developer Documentation and additionally in the Generated API Docs.

Status

Projects / Examples / Templates

(Create a PR to list your work here!)

Getting Started

If you prefer video format: @Milan Jovanoviฤ‡ has created a video crash course to get started!

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!

  1. To get started, create a new project in the Supabase Admin Panel.
  2. Grab your Supabase URL and Supabase Public Key from the Admin Panel (Settings -> API Keys).
  3. 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.

Note for Projects defaulting to System.Text.Json (i.e. Blazor WASM):

You will need to install NewtonsoftJson support:

dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson --version 7.0.5

And include the following in your initialization code:

builder.Services.AddControllers().AddNewtonsoftJson();

Initializing a Client

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();

Using the Client

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.

  1. Supabase.Postgrest
    • Is better accessed using supabase.From<ModelName>() as it provides a wrapper class with some helpful accessors (see below)
  2. Supabase.Realtime
    • If used for listening to postgres_changes can be accessed using: supabase.From<ModelName>().On(listenerType, (sender, response) => {})
    • Otherwise, use Supabase.Realtime.Channel("channel_name") for Broadcast and Presence listeners.
// 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
await supabase.From<TModel>().On(ListenType.All, (sender, response) =>
{
    switch (response.Event)
    {
        case Constants.EventType.Insert:
            break;
        case Constants.EventType.Update:
            break;
        case Constants.EventType.Delete:
            break;
    }

    Debug.WriteLine($"[{response.Event}]:{response.Topic}:{response.Payload.Data}");
});

Notes

  • Be aware that many of the supabase features require permissions for proper access from a client. This is especially true for realtime, postgres, and storage. 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.Realtime is, 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.

Initializing a Client (with Gotrue/Auth Session Persistence)

You can specify a session handler to persist user sessions in your app. For example:

CustomSessionHandler.cs

class CustomSessionHandler : IGotrueSessionPersistence<Session>
{
    public void SaveSession(Session session)
    {
        // Persist Session in Filesystem or in browser storage
        // JsonConvert.SerializeObject(session) will be helpful here!
        throw new NotImplementedException();
    }

    public void DestroySession()
    {
        // Destroy Session on Filesystem or in browser storage
        throw new NotImplementedException();
    }

    public Session LoadSession()
    {
        // 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();

Package made possible through the efforts of:

Join the ranks! See a problem? Help fix it!

Made with contrib.rocks.

Contributing

We are more than happy to have contributions! Please submit a PR.

More Repositories

1

postgres_lsp

A Language Server for Postgres
Rust
3,188
star
2

nextjs-openai-doc-search

Template for building your own custom ChatGPT style doc search powered by Next.js, OpenAI, and Supabase.
TypeScript
1,249
star
3

copycat

Generate deterministic fake values: The same input will always generate the same fake-output.
TypeScript
734
star
4

supabase-on-aws

Self-hosted Supabase on AWS
TypeScript
382
star
5

supabase-kt

A Kotlin Multiplatform Client for Supabase.
Kotlin
364
star
6

sql-examples

Curated list of SQL to help you find useful script easily ๐Ÿš€
Vue
349
star
7

postgrest-rs

Rust client for PostgREST
Rust
328
star
8

chatgpt-your-files

Production-ready MVP for securely chatting with your documents using pgvector
TypeScript
277
star
9

supabase-custom-claims

How to implement custom claims with Supabase
JavaScript
254
star
10

snapshot

Capture a snapshot (or subset) of your Postgres database whilst transforming the data.
TypeScript
211
star
11

supabase-graphql-example

A HackerNews-like clone built with Supabase and pg_graphql
PLpgSQL
207
star
12

supabase-kubernetes

Helm 3 charts to deploy a Supabase on Kubernetes
Smarty
206
star
13

svelte-kanban

PLpgSQL
203
star
14

nuxt-supabase

A supa simple wrapper around Supabase.js to enable usage within Nuxt.
TypeScript
166
star
15

godot-engine.supabase

A lightweight addon which integrates Supabase APIs for Godot Engine out of the box.
GDScript
159
star
16

postgrest-go

Isomorphic Go client for PostgREST. (Now Updating)
Go
125
star
17

supabase-ui-svelte

Supabase authentication UI for Svelte
Svelte
120
star
18

postgrest-csharp

A C# Client library for Postgrest
C#
114
star
19

firebase-to-supabase

Firebase to Supabase Migration Guide
JavaScript
100
star
20

vue-supabase

A supa simple wrapper around Supabase.js to enable usage within Vue.
TypeScript
86
star
21

expo-stripe-payments-with-supabase-functions

Bring the Func(๐Ÿ•บ)
TypeScript
79
star
22

svelte-supabase

JavaScript
71
star
23

realtime-csharp

A C# client library for supabase/realtime.
C#
69
star
24

partner-gallery-example

Supabase Partner Gallery Example
TypeScript
67
star
25

supabase-sveltekit-example

Svelte
65
star
26

supabase-flutter-quickstart

Flutter implementation of the Quickstart Supabase User Management app.
C++
61
star
27

deno-fresh-openai-doc-search

Template for building your own custom ChatGPT style doc search powered by Fresh, Deno, OpenAI, and Supabase.
TypeScript
60
star
28

supabase-traefik

Python
57
star
29

flutter-stripe-payments-with-supabase-functions

Dart
55
star
30

auth-py

Python client implementation for Supabase Auth
Python
54
star
31

supabase-terraform

HCL
53
star
32

postgrest-kt

Postgrest Kotlin Client
Kotlin
52
star
33

flutter-auth-ui

Supabase Auth UI library for Flutter
Dart
49
star
34

supabase-rb

An isomorphic Ruby client for Supabase.
Ruby
46
star
35

realtime-swift

A Swift client for Supabase Realtime server.
Swift
45
star
36

supabase-by-example

TypeScript
44
star
37

flutter-chat

Simple chat application built with Flutter and Supabase.
Dart
44
star
38

postgrest-swift

Swift client for PostgREST
Swift
43
star
39

gotrue-csharp

C# implementation of Supabase's GoTrue
C#
38
star
40

supabase-vscode-extension

Supabase Extension for VS Code and GitHub Copilot.
TypeScript
35
star
41

postgrest-rb

Isomorphic Ruby client for PostgREST.
Ruby
32
star
42

gotrue-swift

A Swift client library for GoTrue.
Swift
32
star
43

storage-go

Storage util client for Supabase in Go
Go
31
star
44

vec2pg

Migrate vector workloads to Postgres
Python
29
star
45

chatgpt-plugin-template-deno

Template for building ChatGPT Plugins in TypeScript that run on Supabase's custom Deno Edge Runtime.
TypeScript
27
star
46

storage-swift

Swift client library to interact with Supabase Storage
Swift
25
star
47

base64url-js

Pure TypeScript implementation of Base64-URL encoding for JavaScript strings.
TypeScript
22
star
48

gotrue-kt

Kotlin Client for GoTrue API
Kotlin
21
star
49

storage-csharp

A C# implementation of Supabase's Object Storage API
C#
19
star
50

postgrest-ex

Elixir Client library for PostgREST
Elixir
18
star
51

gotrue-ex

An Elixir client for the GoTrue authentication service
Elixir
16
star
52

heroku-to-supabase

Heroku to Supabase Migration Guide
16
star
53

sql-to-rest

SQL to PostgREST translator
TypeScript
15
star
54

nuxt3-quickstarter

CSS
13
star
55

gotrue-go

Typed Golang cilent for the Supabase fork of GoTrue
Go
12
star
56

sveltekit-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with SvelteKit.
TypeScript
11
star
57

supabase-php

PHP
11
star
58

pg_headerkit

A set of functions for adding special features to your application that uses PostgREST API calls to your PostgreSQL database.
PLpgSQL
11
star
59

functions-csharp

C# client for interacting with Supabase Functions
C#
11
star
60

gotrue-java

A Java client library for the GoTrue API.
Java
10
star
61

onesignal

Next.js app showcasing how you can implement push notification using OneSignal and Supabase
TypeScript
10
star
62

postgres-wasm-fdw

A WebAssembly foreign data wrapper example project
Rust
9
star
63

functions-swift

Swift Client library to interact with Supabase Functions.
Swift
8
star
64

supabase-adminpack

A Trusted Language Extension containing a variety of useful databse admin queries.
8
star
65

functions-go

Golang client library to interact with Supabase Functions.
Go
7
star
66

unboring.sg

A website and browser extensions to discover things to eat, do, and learn.
TypeScript
7
star
67

supabase-community-bot

TypeScript
5
star
68

ai-writer

An AI writing assistant powered by OpenAI, Supabase, and Next.js
TypeScript
5
star
69

functions-py

Python
5
star
70

storage-java

A Java client library for the Supabase Storage API
Java
4
star
71

supabase-management-js

Convenience wrapper for the Supabase Management API: https://supabase.com/docs/reference/api/introduction
TypeScript
4
star
72

supabase-go

Go
4
star
73

deno-supabase-js

Using supabase-js in Deno.
4
star
74

launchweek.dev

Tracking launch weeks across the industry, for product discovery and inspiration.
JavaScript
3
star
75

.github

Supabase Community
3
star
76

core-swift

Shared interfaces and helpers for Swift libraries
Swift
2
star
77

supa-jam

TypeScript
2
star
78

nftree-garden

Mint an NFT, plant a Tree!
JavaScript
1
star
79

realtime-go

1
star
80

functions-rs

Rust
1
star
81

squad

1
star
82

gotrue-php

PHP
1
star
83

storage-php

PHP
1
star
84

postgrest-php

PHP
1
star
85

deno-storage-js

Repo to overwrite https://deno.land/x/storagee listing.
1
star
86

supabase-fastify-api

TypeScript
1
star
87

gotrue-fsharp

F# client for interacting with Supabase GoTrue
F#
1
star
88

realtime-php

1
star
89

core-py

Shared interfaces and helpers for the supabase-py libs
Python
1
star
90

hacktoberfest-hackathon-template

Template for the Supabase Hacktoberfest Hackathon that follows https://hacktoberfest.digitalocean.com/resources/maintainers
1
star
91

postgrest-java

1
star