下载代码

git clone https://gitee.com/memfiredb/supabase.git

创建应用

登录memfire cloud创建应用,并获取服务地址以及token信息.

avatar

Anon public是客户端API密钥。它允许“匿名访问”您的数据库,直到用户登录。登录后,密钥将切换到用户自己的登录令牌。这将为数据启用行级安全性。 注意:service_role secret可以绕过任何安全策略完全访问您的数据。这些密钥必须保密,并且要在服务器环境中使用,决不能在客户端或浏览器上使用。 在后续示例代码中,需要提供supabaseUrl和supabaseKey。

配置访问秘钥

将上一步中获取的anon public和网址分别设置到supabaseUrl和supabaseKey中 supabase/examples/vue3-ts-todo-list/src/lib/supabase.ts avatar

创建数据表

找到该对应的数据库,点击在线sql编辑器按钮,创建表及安全策略 avatar 建表语句如下:

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/vue3-ts-todo-list
npm install
npm run serve

avatar

avatar

results matching ""

    No results matching ""