HOME / STUDY / 项目记录
项目记录·2026.10.28·18 MIN

用 Supabase 做匿名提问箱的审核队列

提问箱的要求很明确:谁都能匿名写,但只有审核通过的才能被看到。

表结构

create table ask_message (
  id          uuid primary key default gen_random_uuid(),
  content     text not null check (char_length(content) between 1 and 1000),
  contact     text,
  status      text not null default 'pending'
              check (status in ('pending', 'approved', 'rejected')),
  reply       text,
  created_at  timestamptz not null default now(),
  ip_hash     text
);

ip_hash 只存哈希,用来做频率限制,不存原始 IP。

权限策略

匿名写入走 anon 角色,只给 insert,不给 select:

alter table ask_message enable row level security;

create policy "anyone_can_ask"
  on ask_message for insert
  to anon
  with check (status = 'pending');

create policy "owner_reads_everything"
  on ask_message for select
  to authenticated
  using (auth.uid() = '...'::uuid);

create policy "public_reads_approved"
  on ask_message for select
  to anon
  using (status = 'approved');

还没做的部分

频率限制先靠 Edge Function 里的计数器,后面如果被刷,再上验证码;敏感词表目前只有几十个词,需要逐步补。

评论