← Tüm yazılar
ai-basics 8 dk okuma

Supabase ile ilk projen: auth + CRUD + RLS 30 dakikada

Supabase'i sıfırdan kur, magic link auth ekle, tablo oluştur, row level security yaz — 30 dakikada çalışan backend.

Supabase ile İlk Projen

Supabase = açık kaynak Firebase alternatifi. PostgreSQL + Auth + Realtime + Storage + Edge Functions. Çoğu AI ürün için yeterli backend.

1. Proje Oluştur (2 dk)

1. [supabase.com](https://supabase.com) → New Project

2. Proje adı, şifre, region (eu-central-1 Türkiye'ye yakın) seç

3. 30 saniye bekle → proje hazır

2. Tablo Oluştur (5 dk)

SQL Editor'a git, şunu çalıştır:

create table posts (

id bigint generated always as identity primary key,

user_id uuid references auth.users(id),

title text not null,

content text not null,

created_at timestamptz default now()

);

3. Row Level Security (RLS) (5 dk)

RLS = "bu satırı kim görebilir/düzenleyebilir?" kuralları.

alter table posts enable row level security;

-- Herkes okuyabilir

create policy "Public read" on posts

for select using (true);

-- Sadece giriş yapmış kullanıcı yazabilir

create policy "Auth create" on posts

for insert with check (auth.uid() is not null);

-- Sadece kendi yazısını silebilir

create policy "Own delete" on posts

for delete using (auth.uid() = user_id);

4. Auth (5 dk)

Supabase auth magic link ile çalışır — kullanıcı email girer, link alır, tıklar, giriş yapar. Şifre yok.

import { createClient } from '@supabase/supabase-js'

const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY)

// Magic link gönder

await supabase.auth.signInWithOtp({

email: 'user@example.com'

})

// Session kontrol

const { data: { user } } = await supabase.auth.getUser()

5. CRUD (10 dk)

// Create

await supabase.from('posts').insert({

title: 'İlk yazım',

content: 'Supabase harika!',

user_id: user.id

})

// Read

const { data: posts } = await supabase

.from('posts')

.select('*')

.order('created_at', { ascending: false })

// Update

await supabase.from('posts').update({ title: 'Güncel başlık' }).eq('id', 1)

// Delete

await supabase.from('posts').delete().eq('id', 1)

Sonuç

30 dakikada: PostgreSQL veritabanı, kullanıcı auth'u, güvenlik kuralları ve tam CRUD. Ücretsiz tier 2 proje, 500MB database, 50k auth kullanıcısı destekler. AI ürün backend'i için yeterli başlangıç.

İlgili yazılar