Acesse supabase.com → crie um projeto → vá em Project Settings → API e copie a Project URL e a chave anon public.
2
No painel, vá em SQL Editor → cole e execute o SQL abaixo para criar todas as tabelas incluindo autenticação.
3
Em Authentication → Providers, certifique-se que Email está habilitado. Cole as credenciais e conecte.
▸ Mostrar SQL completo (com auth + perfis)
-- ═══════════════════════════════════════════
-- FLEETPRO — Schema completo com Auth + Perfis
-- Execute no SQL Editor do Supabase
-- ═══════════════════════════════════════════
create extension if not exists "uuid-ossp";
-- ── PERFIS DE USUÁRIO (vinculado ao auth.users) ──
create table perfis (
id uuid primary key references auth.users(id) on delete cascade,
nome text not null,
email text not null,
perfil text not null default 'atendente'
check (perfil in ('admin','atendente','investidor')),
ativo boolean default true,
created_at timestamptz default now()
);
-- ── CLIENTES ──
create table clientes (
id uuid primary key default uuid_generate_v4(),
nome text not null,
cpf text unique not null,
email text,
telefone text,
cnh text,
cnh_validade date,
endereco text,
observacoes text,
created_at timestamptz default now()
);
-- ── VEÍCULOS ──
create table veiculos (
id uuid primary key default uuid_generate_v4(),
tipo text not null check (tipo in ('carro','moto')),
marca text not null,
modelo text not null,
placa text unique not null,
ano int,
cor text,
cambio text,
km_atual int default 0,
diaria numeric(10,2) not null,
status text default 'disponivel'
check (status in ('disponivel','alugado','manutencao')),
observacoes text,
created_at timestamptz default now()
);
-- ── LOCAÇÕES ──
create table locacoes (
id uuid primary key default uuid_generate_v4(),
veiculo_id uuid references veiculos(id),
cliente_id uuid references clientes(id),
data_inicio date not null,
data_fim date not null,
km_inicial int,
km_final int,
diaria numeric(10,2),
total numeric(10,2),
status text default 'ativa'
check (status in ('ativa','encerrada','cancelada')),
observacoes text,
criado_por uuid references auth.users(id),
created_at timestamptz default now()
);
-- ── MANUTENÇÕES ──
create table manutencoes (
id uuid primary key default uuid_generate_v4(),
veiculo_id uuid references veiculos(id),
tipo text not null,
descricao text,
custo numeric(10,2),
data_inicio date not null,
data_fim date,
oficina text,
status text default 'pendente'
check (status in ('pendente','em_andamento','concluida')),
created_at timestamptz default now()
);
-- ── RLS ──
alter table perfis enable row level security;
alter table clientes enable row level security;
alter table veiculos enable row level security;
alter table locacoes enable row level security;
alter table manutencoes enable row level security;
-- Perfis: cada user vê o próprio; admin vê todos
create policy "Ver proprio perfil" on perfis for select using (auth.uid() = id);
create policy "Admin ve todos perfis" on perfis for all using (
exists (select 1 from perfis where id = auth.uid() and perfil = 'admin')
);
-- Veículos: todos autenticados leem; só admin/atendente escrevem
create policy "Autenticados leem veiculos" on veiculos for select using (auth.role() = 'authenticated');
create policy "Admin atendente escrevem veiculos" on veiculos for all using (
exists (select 1 from perfis where id = auth.uid() and perfil in ('admin','atendente'))
);
-- Clientes: admin e atendente acessam
create policy "Admin atendente clientes" on clientes for all using (
exists (select 1 from perfis where id = auth.uid() and perfil in ('admin','atendente'))
);
-- Locações: todos leem; admin/atendente escrevem
create policy "Autenticados leem locacoes" on locacoes for select using (auth.role() = 'authenticated');
create policy "Admin atendente escrevem locacoes" on locacoes for all using (
exists (select 1 from perfis where id = auth.uid() and perfil in ('admin','atendente'))
);
-- Manutenções: todos leem; admin escreve
create policy "Autenticados leem manutencoes" on manutencoes for select using (auth.role() = 'authenticated');
create policy "Admin escreve manutencoes" on manutencoes for all using (
exists (select 1 from perfis where id = auth.uid() and perfil = 'admin')
);
-- ── TRIGGER: criar perfil ao registrar usuário ──
create or replace function handle_new_user()
returns trigger as $$
begin
insert into perfis (id, nome, email, perfil)
values (
new.id,
coalesce(new.raw_user_meta_data->>'nome', split_part(new.email,'@',1)),
new.email,
coalesce(new.raw_user_meta_data->>'perfil', 'atendente')
);
return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
after insert on auth.users
for each row execute function handle_new_user();
-- ── DADOS DE EXEMPLO ──
insert into veiculos (tipo,marca,modelo,placa,ano,cor,cambio,km_atual,diaria,status) values
('carro','Honda','Civic','ABC-1234',2022,'Prata','Automatico',32100,180,'disponivel'),
('carro','Chevrolet','Onix','DEF-5678',2021,'Branco','Manual',48900,120,'disponivel'),
('carro','Hyundai','HB20','PQR-2244',2023,'Vermelho','Automatico',12400,160,'disponivel'),
('moto','Honda','CB 300','XYZ-9988',2023,'Preta','Manual',8400,90,'disponivel'),
('moto','Yamaha','Fazer 250','GHI-3322',2022,'Azul','Manual',15700,80,'disponivel'),
('moto','Honda','Biz 125','JKL-5544',2021,'Vermelha','Manual',22000,60,'disponivel');
insert into clientes (nome,cpf,email,telefone,cnh,cnh_validade) values
('Ana Lima','123.456.789-00','[email protected]','(21) 99999-1111','AB123456','2028-06-15'),
('Carlos M.','987.654.321-00','[email protected]','(21) 98888-2222','CD789012','2025-04-30'),
('Fernanda T.','456.789.123-00','[email protected]','(21) 97777-3333','EF345678','2027-11-20');
Project Settings → API → Project URL
Project Settings → API → anon public (começa com eyJ)
✅ URL correta: https://abc123.supabase.co
✅ Chave correta: eyJhbGci... (longa, começa com eyJ)