Backend Development with Supabase
Supabase is rapidly gaining popularity as an open-source Firebase alternative. It stands out with its PostgreSQL-based structure and powerful features.
Why Supabase?
Basic Usage
import { createClient } from '@supabase/supabase-js'const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
)
// Fetching data
const { data, error } = await supabase
.from('posts')
.select('*')
.order('created_at', { ascending: false })
// Inserting data
const { data, error } = await supabase
.from('posts')
.insert({ title: 'New Post', content: 'Content' })
Authentication
// Email signup
const { data, error } = await supabase.auth.signUp({
email: 'user@example.com',
password: 'password123'
})// Google login
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google'
})
Real-time Subscriptions
const channel = supabase
.channel('posts')
.on('postgres_changes',
{ event: '*', schema: 'public', table: 'posts' },
(payload) => {
console.log('Change:', payload)
}
)
.subscribe()
Conclusion
Supabase is an excellent backend solution for modern web and mobile applications. Being open source and using PostgreSQL makes it different from Firebase.