下载代码
git clone https://gitee.com/memfiredb/supabase.git
创建应用
登录memfire cloud创建应用,并获取服务地址以及token信息.
Anon public是客户端API密钥。它允许“匿名访问”您的数据库,直到用户登录。登录后,密钥将切换到用户自己的登录令牌。这将为数据启用行级安全性。 注意:service_role secret可以绕过任何安全策略完全访问您的数据。这些密钥必须保密,并且要在服务器环境中使用,决不能在客户端或浏览器上使用。 在后续示例代码中,需要提供REACT_APP_SUPABASE_URL和REACT_APP_SUPABASE_KEY。
配置访问密钥
将上一步中获取的anon public和网址分别设置到REACT_APP_SUPABASE_KEY和REACT_APP_SUPABASE_URL中
supabase/examples/react-todo-list/src/lib/constants.js
创建数据表
找到该对应的数据库,点击在线sql编辑器按钮,创建表及安全策略
建表语句如下:
create table public.todos (
id bigint generated by default as identity primary key,
user_id uuid references auth.users not null,
task text check (char_length(task) > 3),
is_complete boolean default false,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);
create index idx_todos_uid on public.todos (user_id);
alter table public.todos enable row level security;
create policy "Individuals can create todos." on public.todos for
insert with check (auth.uid() = user_id);
create policy "Individuals can view their own todos. " on public.todos for
select using (auth.uid() = user_id);
create policy "Individuals can update their own todos." on public.todos for
update using (auth.uid() = user_id);
create policy "Individuals can delete their own todos." on public.todos for
delete using (auth.uid() = user_id);
运行程序
node -v # v14.16.0
npm config set registry https://registry.npm.taobao.org
cd supabase/examples/react-todo-list
npm install
npm run start --host 0.0.0.0