Connecting an app to your backend
Your app needs two values from the backend’s page in the console: the URL and the anon key. Both are shown in full underAPI keys, each with a Copy button.
The Connect your app box under them already contains your real values, so you
can copy the code from there instead of typing anything.
The anon key is made to be used in browser code, as long as row security is on
for your tables. The service key is not. It bypasses row security, so it never
goes in browser code and it is never part of the Connect your app box. The page
on keys explains the difference.
supabase-js
Install the client:Lovable
A Lovable project reads two variables when it builds. Put these two lines in your project’s.env file:
VITE_SUPABASE_ANON_KEY. If your project already uses that name, keep it and put
the anon key there. A project that also wants the backend’s reference reads it
from VITE_SUPABASE_PROJECT_ID. The reference is the short random code at the
start of your URL.
Server code that uses TanStack Start reads the same three values under names
without the VITE_ prefix:
SUPABASE_URLSUPABASE_PUBLISHABLE_KEYSUPABASE_PROJECT_ID
If the connection fails
- Check that the URL has no extra characters and starts with
https://. - Check that you pasted the anon key and not the service key.
- If you regenerated the keys, your app still has the old ones. Copy the new values from the console and rebuild.