CREATE POLICY select_book_configs ON public.book_configs FORSELECTto authenticated USING ((select auth.uid()) = user_id); CREATE POLICY insert_book_configs ON public.book_configs FORINSERTto authenticated WITHCHECK ((select auth.uid()) = user_id); CREATE POLICY update_book_configs ON public.book_configs FORUPDATEto authenticated USING ((select auth.uid()) = user_id); CREATE POLICY delete_book_configs ON public.book_configs FORDELETEto authenticated USING ((select auth.uid()) = user_id);
createtable public.book_notes ( user_id uuid notnull, book_hash text notnull, id text notnull, type text null, cfi text null, text text null, style text null, color text null, note text null, created_at timestampwithtime zone nulldefault now(), updated_at timestampwithtime zone nulldefault now(), deleted_at timestampwithtime zone null, constraint book_notes_pkey primary key (user_id, book_hash, id), constraint book_notes_user_id_fkey foreign KEY (user_id) references auth.users (id) ondelete CASCADE ) TABLESPACE pg_default;
CREATE POLICY select_book_notes ON public.book_notes FORSELECTto authenticated USING ((select auth.uid()) = user_id); CREATE POLICY insert_book_notes ON public.book_notes FORINSERTto authenticated WITHCHECK ((select auth.uid()) = user_id); CREATE POLICY update_book_notes ON public.book_notes FORUPDATEto authenticated USING ((select auth.uid()) = user_id); CREATE POLICY delete_book_notes ON public.book_notes FORDELETEto authenticated USING ((select auth.uid()) = user_id);
-- Create the `files` table createtable public.files ( id uuid notnulldefault gen_random_uuid (), user_id uuid notnull, book_hash text null, file_key text notnull, file_size bigintnotnull, created_at timestampwithtime zone nulldefault now(), deleted_at timestampwithtime zone null, constraint files_pkey primary key (id), constraint files_file_key_key unique (file_key), constraint files_user_id_fkey foreign KEY (user_id) references auth.users (id) ondelete CASCADE ) TABLESPACE pg_default;
-- Add an index for efficient querying by user_id and deleted_at create index idx_files_user_id_deleted_at on public.files (user_id, deleted_at);
create index idx_files_file_key on public.files (file_key);
create index idx_files_file_key_deleted_at on public.files (file_key, deleted_at);
-- Enable RLS on the `files` table altertable public.files enable row level security;
create policy "Users can insert their own files" on public.files forinsert withcheck ( auth.uid() = user_id );
create policy "Users can view their own active files" on public.files forselect using ( auth.uid() = user_id and deleted_at isnull );
create policy "Users can soft-delete their own files" on public.files forupdate using ( auth.uid() = user_id ) withcheck ( deleted_at isnullor deleted_at > now() );
create policy "Users can delete their own files permanently" on public.files fordelete using ( auth.uid() = user_id );
配置 Supabase 中的 site URL
在 Supabase 仪表盘中找到 Authentication(左侧) > site URL 把 site URL 改为网站 URL
感谢分享!
不明觉历呀。
微信阅读,目前感觉还行。每天打卡。