17 lines
1.1 KiB
SQL
17 lines
1.1 KiB
SQL
-- Personal tokens for the MCP endpoint (/api/mcp): an AI app such as Claude Code connects with one and acts as you,
|
|||
|
|
-- summary only. Only a hash is stored; the token itself is shown once. You see and revoke your own; the server checks them.
|
||
|
|
create table if not exists public.mcp_tokens (
|
||
|
|
id uuid primary key default gen_random_uuid(),
|
||
|
|
user_id uuid not null references auth.users on delete cascade,
|
||
|
|
token_hash text not null unique,
|
||
|
|
label text not null default 'Claude',
|
||
|
|
created_at timestamptz not null default now(),
|
||
|
|
last_used_at timestamptz
|
||
|
|
);
|
||
|
|
create index if not exists mcp_tokens_user on public.mcp_tokens (user_id);
|
||
|
|
alter table public.mcp_tokens enable row level security;
|
||
|
|
drop policy if exists "own" on public.mcp_tokens;
|
||
|
|
create policy "own" on public.mcp_tokens for select to authenticated using (user_id = (select auth.uid()));
|
||
|
|
drop policy if exists "own delete" on public.mcp_tokens;
|
||
|
|
create policy "own delete" on public.mcp_tokens for delete to authenticated using (user_id = (select auth.uid()));
|
||
|
|
grant select (id, user_id, label, created_at, last_used_at), delete on public.mcp_tokens to authenticated;
|