What is Supabase?

When building your next application, particularly one that demands a robust backend, you might need to be torn between popular options like Firebase and lesser-known alternatives. If you value open-source software, customisation, and control over your infrastructure, Supabase could be the perfect fit for you.

Supabase is an open-source toolbox for building applications, particularly ones that need a backend, built on the PostgreSQL relational database. It is an alternative to Firebase. Firebase uses a NoSQL document store while Supabase uses a relational database management system.

If you value open-source software, customisation, and control over your backend infrastructure, Supabase allows for self-hosting and modifying the codebase, unlike Firebase’s proprietary nature. Supabase’s free tier is generous, and its pay-as-you-go pricing might be more cost-effective depending on your project’s resource consumption compared to Firebase’s pricing structure.

Now Let’s Understand the Database connection and Auth in Supabase:

Database Connection Methods in Supabase :

Supabase provides several options for programmatically connecting to your Postgres database:

  1. Programmatic access using the Data APIs -
    This method is ideal for front-end applications where you interact with the database through an SDK. Supabase provides official client libraries for Javascript, Typescript, Python, Go, etc., that handles authentication and data formatting for you.

  2. Connection pooling for scalable connections-
    This method is available in 2 modes: Transaction and Session :
    Transaction: If you are using your application in serverless env, that is connecting to the database and disconnecting them immediately then use connection pooler with transaction mode.
    Session: If you need a longer-lived connection then use connection pooling with session mode.

Understanding Connection Pooling in Supabase

3. Direct connections — using the built-in Postgres connection system: If you are connected to the database and if your network supports Ipv6 then use the Direct connection method.

Supabase Auth with JWTs and RLS:

Supabase Auth uses JSON Web Tokens (JWTs) for authentication. Auth integrates with Supabase’s database features, making it easy to use Row Level Security (RLS) for authorization.

  • Supabase Auth leverages JSON Web Tokens (JWTs) to authenticate users. These tokens act as secure credentials that verify a user’s identity.

  • It integrates seamlessly with Supabase’s database, allowing you to implement Row-Level Security (RLS) for authorization. RLS controls data access based on user roles or attributes.

The Four Layers of Supabase Auth

  • Client Layer: This is the interface your application uses to interact with Supabase Auth. It can be a Supabase client SDK (e.g., Javascript, Python) or custom HTTP requests.

  • Kong API Gateway: A shared gateway that routes requests to various Supabase services, including Auth. It centralizes API access management. You can deep dive into the Kong API gateway from here.

  • Auth Service (Formerly GoTrue): This service handles user authentication functions (sign-up, sign-in, password resets) and JWT management. It interacts with the Postgres database.

  • Postgres Database: Supabase stores user data and Auth information in a dedicated schema within this database.

Layer’s of Supabse Auth

Enabling Authentication Methods

Supabase allows you to activate the specific authentication methods you require through project settings. These methods can include password-based login, magic links, social logins (e.g., GitHub), and Single Sign-On (SSO).

Using Supabase Auth in Your Project: Three Approaches

  1. The API: Interact directly with the Auth service via API calls. You can send user information to designated endpoints for sign-up, user management, and token retrieval.

  2. The SDKs: Utilize Supabase’s client SDKs for various programming languages. These libraries simplify authentication tasks and provide a more structured approach.

  3. Auth UI Helpers: Supabase offers Auth UI Helpers to facilitate user sign-up, sign-in, and password reset with pre-built UI components.

In essence, Supabase offers more flexibility and control through its open-source, SQL-based approach, while Firebase provides a convenient and well-supported managed backend solution. The best choice depends on your specific project requirements and priorities.

References: Supabase DocsSupabase vs firebaseSupabase Auth

0
Subscribe to my newsletter

Read articles from NonStop io Technologies directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

NonStop io Technologies
NonStop io Technologies

Product Development as an Expertise Since 2015 Founded in August 2015, we are a USA-based Bespoke Engineering Studio providing Product Development as an Expertise. With 80+ satisfied clients worldwide, we serve startups and enterprises across San Francisco, Seattle, New York, London, Pune, Bangalore, Tokyo and other prominent technology hubs.