App SvelteKit privata (static deploy) con Supabase Auth + Postgres RLS.
- SvelteKit + TypeScript
@sveltejs/adapter-staticcon fallback404.html- Supabase (
@supabase/supabase-js) - Deploy su GitHub Pages via GitHub Actions
- Installa dipendenze:
npm install- Crea
.env:
PUBLIC_SUPABASE_URL=https://<project-ref>.supabase.co
PUBLIC_SUPABASE_ANON_KEY=<anon-key>
BASE_PATH=- Avvia:
npm run dev- Crea un progetto Supabase.
- In Authentication > Providers abilita Google e configura Client ID/Secret.
- In Authentication > URL Configuration imposta:
- Site URL: URL GitHub Pages (es.
https://<user>.github.io/<repo>) - Redirect URLs:
http://localhost:5173/apphttps://<user>.github.io/<repo>/app
- Site URL: URL GitHub Pages (es.
- Esegui SQL nell'ordine:
supabase/sql/01_schema.sqlsupabase/sql/02_rls.sql
- Inserisci whitelist iniziale (SQL editor):
insert into public.allowed_emails (email, is_admin)
values
('admin@example.com', true),
('friend@example.com', false)
on conflict (email) do update
set is_admin = excluded.is_admin;- Vai in Table Editor → schema
public→ tabellaallowed_emails. - Aggiungi/modifica le righe con:
email(chiave primaria)is_admin(true/false)
- In alternativa usa SQL Editor con
insert ... on conflictcome nell'esempio sopra.
- L'app usa solo
PUBLIC_SUPABASE_URLePUBLIC_SUPABASE_ANON_KEYlato client. - Le policy si basano su
auth.jwt()->>'email'per whitelist/admin (is_allowed_user,is_admin_user). profiles_publicè una vista con campi minimi (id,first_name,last_name,avatar_id) per homepage, evitando esposizione dibirth_datead altri utenti.
Workflow: .github/workflows/deploy.yml
- Trigger su push in
main - Node 20
npm install+npm run buildupload-pages-artifact+deploy-pages
Nel repository GitHub, Settings > Secrets and variables > Actions:
PUBLIC_SUPABASE_URLPUBLIC_SUPABASE_ANON_KEY
Nel workflow è impostato automaticamente a /${{ github.event.repository.name }}.
Se devi pubblicare su dominio custom/root path, cambia BASE_PATH nel workflow (ad esempio stringa vuota).
src/routes/login: login Google OAuthsrc/routes/app: area protettasrc/routes/app/profile: profilo utentesrc/routes/app/admin: gestione closures + warning homepagesupabase/sql: schema e RLS