برای اتصال چتروم به سوپابیس، مشخصات زیر را از منوی Project Settings > API در داشبورد Supabase خود کپی و در این بخش وارد کنید:
public/supabase-config.js نیز قرار دهید.
مراحل راهاندازی در داشبورد Supabase:
-- ۰. خروج از حالت Read-Only در صورت قفل بودن سشن
set session characteristics as transaction read write;
set default_transaction_read_only = 'off';
-- ۱. ساخت جدول پیامها
create table if not exists public.messages (
id uuid default gen_random_uuid() primary key,
username text not null,
content text not null,
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- ۲. فعالسازی RLS
alter table public.messages enable row level security;
-- ۳. دسترسی خواندن برای عموم
drop policy if exists "Allow public read access" on public.messages;
create policy "Allow public read access"
on public.messages for select to anon, authenticated using (true);
-- ۴. دسترسی ارسال پیام برای عموم
drop policy if exists "Allow public insert access" on public.messages;
create policy "Allow public insert access"
on public.messages for insert to anon, authenticated with check (
length(trim(content)) > 0 and length(trim(username)) > 0 and length(content) <= 1000
);
-- ۵. فعالسازی Realtime روی جدول
alter table public.messages replica identity full;
do $$
begin
if not exists (
select 1 from pg_publication_tables
where pubname = 'supabase_realtime' and schemaname = 'public' and tablename = 'messages'
) then
alter publication supabase_realtime add table public.messages;
end if;
end $$;
-- ۶. ایندکس زمانی
create index if not exists idx_messages_created_at on public.messages (created_at desc);