Supabase: Free Open-Source Firebase Alternative with 68.8K Stars

Supabase is making waves as an open-source backend solution that replicates much of Firebase’s functionality using enterprise-grade tools. With an impressive 68.8K stars on its GitHub repository, Supabase’s popularity is soaring.

GitHub: https://github.com/supabase/supabase

Under the hood, Supabase combines a PostgreSQL database with an array of essential backend features, including REST and GraphQL APIs, real-time data subscriptions, edge and database functions, user authentication, and even file storage. It’s a full-fledged backend-as-a-service (BaaS) platform.

One of the most appealing aspects of Supabase is its generous free tier, which allows you to spin up two database-driven applications complete with authentication. It’s perfect for small projects and proofs-of-concept.

Supabase’s feature set is comprehensive and constantly expanding. Beyond the core database and API functionality, recent additions include a vector database and AI-powered vector/embedding toolkit. This opens up exciting possibilities like retrieval augmented generation (RAG).

Implementing Supabase authentication in a framework like Next.js is incredibly straightforward. After registering and creating a project, you can access your API URL, public key, and private key (which should be kept securely on the server-side).

Supabase supports numerous auth providers, but email/password is one of the simplest. With just a few lines of code to call the signUp and signIn API methods, you can have a working auth system that automatically syncs with your database’s users table.

For a cleaner implementation, consider using Next.js server actions. Create a Supabase client, extract the form data, make the API call, and redirect based on the response. Cookies allow the server to recognize authenticated users on future requests.

Supabase’s powerful permission system makes it effortless to control data access at a granular level. You can define policies that restrict users to editing only their own posts, for instance, without writing any additional code.

With built-in file storage and a free vector database enabling advanced AI functionality, Supabase is an incredibly versatile and generous platform for building backend services. Its ease of use and extensive feature set make it a compelling alternative to Firebase.

Here’s an example of using Supabase authentication in Next.js:

// app/actions.ts
'use server'

import { redirect } from 'next/navigation' 
import { createClient } from '@/lib/supabaseClient'

export async function createUser(formData: FormData) {
  const supabase = createClient()
  const email = formData.get('email') 
  const password = formData.get('password')

  const { user, error } = await supabase.auth.signUp({
    email,
    password,
  })

  if (error) {
    console.error('Error:', error.message)
    return redirect('/error')
  }

  await supabase.auth.signInWithPassword({
    email,
    password,
  })

  redirect('/dashboard')
}
// app/login/page.tsx
import { createUser } from './actions'

export default function LoginPage() {
  return (
    <form action={createUser}>
      <input type="email" name="email" />
      <input type="password" name="password" />
      <button type="submit">Sign Up</button>
    </form>
  )
}

Supabase is rapidly evolving and adding new features all the time. With its powerful tools, generous free tier, and strong community, it’s definitely worth considering for your next project’s backend needs.

Categories: GitHub
X