zoedsoupe

zoedsoupe

Supabase Potion - a magic and lovely way to interact with Supabase

Hello alchemists! I’m here to present about a new way to interact with Supabase services: supabase-potion made with love and magic by @zoedsoupe :purple_heart:

What it is?

supabase-potion is a client library that provides a developer-friendly interface to interact with various of Supabase services. It highly integrates with OTP, meaning that it can handle thousands of different clients/connections.

It also provides friendly error messages and error return from all functions, meaning that you can simply pattern match on all pre-discovered error messages/error codes from Supabase APIs.

Finally, the idea behind this client library is to provide a similidar API as those other Supabase clients for Go,Javascript, Rust and other, in the meaning of quality, folowwing good practices of the language itself and provide a composable interface.

Why another Supabase client library?

There is also some offical attempts to provide Supabase integration in the elixir world, like:

Which are awesome libraries! However they have some negative points, like:

  • doesn’t provide a friendly way to integrate each library with each other
  • doesn’t use OTP benefits, supervision trees or concurrency, they seem to be done on a scripint language
  • packages seem to be unmaintained/have no more updates
  • Supabase Realtime and UI (for Live View) are missing implementation
  • GoTrue is missing some important functions and doesn’t have integration with Plug and Live View hooks
  • Storage implementation is incomplete and doesn’t support uploads/downloads with async/streams
  • PostgREST is missing a bunch of functions and doesn’t integrate with ecto

So seeing these points I decided to create my own client library and share with others who would like to test/use Supabase services from our Phoenix applications or other future libraries.

What is currently done?

Supabase Potion

Where all starts! Define client management with DynamicSupervisor and the basic strucutre to interact with other services!

  • init_client/1
  • init_client!/1

To start a client, if the library itself is managing clients, you can safely use:

iex> Supabase.init_client %{name: MyClient}
{:ok, #PID<1.2.3>}

You can also mannually start/manage clients with:

iex> Supabase.Client.start_link(%{name: MyClient})
{:ok, #PID<1.2.3>}

Supabase Storage

The file storage service from Supabase, now completely available to Elixir/Phoenix users! All these functions receive a Supabase.Client definition (either an atom or a pid).

  • the implementation is complete, handles async uploads and downloads from buckets!
  • complete mapping of entities like %Object{} and %Bucket{}

The complete list of current functions are:

Buckets

  • list_buckets/1
  • retrieve_bucket_info/2
  • create_bucket/2
  • update_bucket/2
  • empty_bucket/2
  • delete_bucket/1

Objects

  • remove_object/3
  • move_object/4
  • copy_object/4
  • retrieve_bucket_info/3
  • list_objects/4
  • upload_object/5
  • download_object/3
  • download_object_lazy/3
  • save_object/3
  • save_object_stream/3
  • create_signed_url/4

Supabase Auth/GoTrue

Provide authentication via:

  • email+password
  • oauth
  • otp codes
  • magic links

Also integrates for authentication with Plug and Live View hooks!

Current functions are:

User API

  • get_user/2
  • sign_in_with_password/2
  • sign_up/2

Admin API

  • sign_out/3
  • invite_user_by_email/3
  • create_user/2
  • generate_link/2
  • delete_user/3
  • get_user_by_id/2
  • list_users/2
  • update_user_by_id/3

Plugs

  • VerifyHeader

Roadmap

GoTrue/Auth

  • Finish integration (User API)
  • Implement VerifyCookie Plug
  • Implement VerifySession Plug
  • Implement :ensure_authenticated Live View hook
  • Implement :redirect_if_authenticated Live View hook
  • Implement :mount_current_user Live View hook

Supabase UI

  • Provide function components for Live View
  • Provide Live components for Live View
  • Provide Auth ready-to-use components for Live View

Supabase PostgREST

  • Generate schemas/migrations based on Supabase database schema
  • Provide an way to integrate with ecto via Ecto.Adapter (it’s being discussed in this thread)

Supabase Realtime

  • Provide PubSub adapter for realtime messages
  • Provide Process Messaging adapter to send to whole system

Conclusion

That’s it! I’m really proud of this client library and I really would like people to use, test and contribute in any way to the project! It stills on high development, so expect breaking changes. There are always something to improve, so I’m open to any kind of contribution such as: testers, documentation, code review, feature request and other types of contribution.

Most Liked

zoedsoupe

zoedsoupe

i have some good news! I just launched new updated and refactored versions for the aforementioned hex packages, targeting the base SDK (aka supabase-ex) implementation.

to summarize, i simplified the client initialization and move the decision to manage OTP processes for the final user, as it should be! this should also prevent strange errors on starting and using clients but also clarify the documentation on how to start a client, as in the later version it had around 3 ways to start a client…

so basically, the current state for each library and my current roadmap is (very summarized):

supabase-ex

  • easy manipulation, configuration and initialization of clients
    • supports all available configuration options as supabase-js
    • provides a pre defined “high-level” http client for supabase APIs (it should be refactored in some points)

it have a total of 2422 downloads on hex

postgrest-ex

  • follows the standard of postgrest-js and postgrest-go with composable and “lazy” query and filter builders
  • have good error mapping structure
  • can not only execute queries and return JSON response but also can parse to an Ecto schema/struct
  • good test coverage

it have a total of 242 downloads on hex
elixir community will very often prefer to connect to the postgresql instance directly with ecto

storage-ex

  • handle all bucket operations
  • handle all object operations
    • with addition of stream upload
    • with addition of stream download

it have a total of 802 downloads on hex
for some time the package was broken on hex :confused:

gotrue-ex

  • it have Plug applications support (plug middlewares)
  • it have Phoenix.LiveView applications support (hooks)
  • implements password reset email
  • implements resend of confirmation email
  • implements user update (also admin API)
  • implements signup flow
  • implements user creation (admin)
  • implements signing in with
    • id token
    • oauth
    • otp
    • email and password
    • sso
  • implements sign out (admin)
  • implements email invitation and link generation (eg. any verification type) (admin)
  • implements user management (deletion, list, get by id, update by id) (admin)

it have a total of 1738 downloads on hex

Roadmap

Said that, i would like to tackle these next features:

  • Supabase.UI library for Phoenix.LiveView
  • Supabase Realtime library and integration
    • as the realtime project is also in Elixir, i was discussing with @filipecabaco about the possibility to create adapters for PubSub and or process messaging to receive updates, besides the API integration
  • Implements anonymous sign in on gotrue-ex
  • Improvements and refactors on the PKCE flow on gotrue-ex
  • integration with Ecto via custom adapter to be able to use Ecto.Query
    easily on postgrest-ex
zoedsoupe

zoedsoupe

So cool! Let’s break on smaller parts:

From the beginning: Supabase is an open source alternative for Firebase but it do can be used from backend servers

PostgreSQL

Supabase offers a dedicated postgresql instance that you can interact with many ways. For elixir/phoenix applications i really recommend to just grab the connection config and link directly with Ecto!

but if eventually you would like to test or build only a “client side app” with live view, you could use the postgrest-ex library that interact with your database instance via HTTP (trough PostgREST project)

MinIO/object storages

Supabase also offers the Supabase Storage feature, the good news is that it supports the S3 protocol, so you don’t need to use storage-ex, you can use directly req_s3 or even ex_aws for S3 services

Self hosting

You can easily self host supabase instances based on their docker-compose, like said is this tutorial: Self-Hosting | Supabase Docs

Conclusion

This library aims to provide an easy, plug n play way to interact with supabase! Also, i do want to build example applications to demonstrate each integration, that’s on the roadmap too

Where Next?

Popular in Announcing Top

martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
mbuhot
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs. Generate and serve a JSON Open API ...
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Thank...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement