Supabase Backend as a Service · Lezione

Collegare l’app al client Supabase

Installi il client JavaScript di Supabase, lo inizializzi con l’URL del progetto e la anon key, quindi esegua la prima richiesta per confermare la connessione.

Lezione 4 di 413 passaggi

Collegare l’app al client Supabase è una lezione Supabase Backend as a Service gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Supabase Backend as a Service, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Supabase Backend as a Service include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

From Dashboard to Code

Dashboard done — now you talk to Supabase from code using its client library. For JavaScript and TypeScript, reach for supabase-js.

Installing the Client

Add the official supabase-js package to your project with your package manager.

npm install @supabase/supabase-js

Where to Find Your Keys

Under Project Settings > API you will find your Project URL, the browser-safe anon key, and the service_role key for servers only.

Creating the Client

Call createClient once with your URL and anon key, then reuse that single instance everywhere in your app.

import { createClient } from '@supabase/supabase-js';
const supabase = createClient(
  'https://your-project.supabase.co',
  'your-anon-key'
);

Keep Secrets in Env Vars

Never hardcode keys in committed code — read them from environment variables instead.

const url = process.env.SUPABASE_URL;
const key = process.env.SUPABASE_ANON_KEY;
console.log('Configured:', Boolean(url && key));

Your First Query

Run your first query with select. The client returns a data array and an error object, never throwing on its own.

const { data, error } = await supabase
  .from('todos')
  .select('*');
if (error) console.error(error.message);
else console.log(data);

Always Handle the Error

Supabase will not throw on a failed query, so check error every time before you touch data.

function handle(result) {
  if (result.error) return 'Failed: ' + result.error;
  return 'Got ' + result.data.length + ' rows';
}
console.log(handle({ data: [1, 2], error: null }));

Inserting Data

Write a row with insert, passing an array of objects. Add select to get the inserted rows back.

const { data, error } = await supabase
  .from('todos')
  .insert([{ title: 'Learn Supabase', done: false }])
  .select();

Client vs Server Keys

The anon key is guarded by Row-Level Security and safe in the browser. The service_role key bypasses RLS, so keep it server-only.

Confirming the Connection

Quick health check: select a single row. Real data or a clear permission error (not a network error) means your client is wired correctly.

Reusing One Instance

Export your configured client from one module and import it everywhere. A single instance avoids duplicate connections and config drift.

Quick Check

Test your understanding of connecting with the client.

Recap

Recap: you installed supabase-js, built a client from env vars, ran your first select and insert, and learned why anon keys are browser-safe.

Gratis per iniziare

Impara Supabase Backend as a Service con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
11
Lezioni
40

Domande Frequenti

La lezione «Collegare l’app al client Supabase» è gratuita?

Sì — il testo completo di «Collegare l’app al client Supabase» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Supabase Backend as a Service, passa a CoddyKit PRO. Il corso Supabase Backend as a Service include 4 lezioni in totale.

Cosa imparerò in «Collegare l’app al client Supabase»?

Installi il client JavaScript di Supabase, lo inizializzi con l’URL del progetto e la anon key, quindi esegua la prima richiesta per confermare la connessione. Eserciti Supabase Backend as a Service con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Supabase Backend as a Service?

Non è richiesta alcuna esperienza precedente. Supabase Backend as a Service su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Collegare l’app al client Supabase»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Supabase Backend as a Service?

Sì. Ogni lezione Supabase Backend as a Service include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Introduzione a BaaS e Supabase
  2. Configurazione del primo progetto
  3. Panoramica della dashboard di Supabase
  4. Collegare l’app al client Supabase
← Torna a Supabase Backend as a Service