Connect to Supabase
Before you start
This guide is for an app that already uses Supabase. moonbase runs your app; your data stays in your Supabase project.
moonbase has its own managed PostgreSQL database too. It is in a closed pilot: customers can't create one yet, and there is no date for wider availability. When a mission has one, its status is in the Database section of the mission's page, and the owner can export it, see Export Your Database. Until then, connect the outside service you already use, as below.
Which value goes in which variable
Take the values from your Supabase project's API settings. Use the variable names your code already reads; these are the usual ones:
• Project URL: NEXT_PUBLIC_SUPABASE_URL (Next.js) or VITE_SUPABASE_URL (Vite). Public.
• anon key, or the newer publishable key: NEXT_PUBLIC_SUPABASE_ANON_KEY or VITE_SUPABASE_ANON_KEY. Public: Supabase designs it to be seen in the browser. What protects your data is Row Level Security, so turn it on, with policies, for every table the browser reads or writes.
• service role key, or the newer secret key: SUPABASE_SERVICE_ROLE_KEY. Server-only. It skips Row Level Security, so it never gets a public prefix and never goes in a browser file.
• Database connection string, only if your server code talks to Postgres directly: DATABASE_URL. Server-only.
Where to enter them
Open your mission in Mission Control and go to Environment Variables. Type each value there. Values are write-only: after a save the screen shows only the name. Secrets go on that screen only, never in a chat with an AI assistant and never in your code or your ZIP.
An assistant connected to moonbase can save the public values for you. For a secret, it sends you to that same screen and you type it yourself.
A change applies on the next deploy: use Save and redeploy, or Deploy new version.
How the values reach your app
How a value reaches your app depends on what kind of mission it is:
• A mission served as it is (an index.html at the root, no build step): moonbase passes it no environment variables at all. Every file in it is public, so it can only hold public values, written straight into the page.
• A front end moonbase builds (Vite, Vue, Create React App, Astro, SvelteKit, Next.js): during the build, moonbase gives the build only the variables that carry the framework's public prefix: NEXT_PUBLIC_ for Next.js, VITE_ for Vite and Vue, REACT_APP_ for Create React App, PUBLIC_ for Astro and SvelteKit. The framework writes those into the files the browser downloads. A value without the prefix never reaches the build.
• Server code (a Next.js server, Express, Nuxt, SvelteKit with the Node adapter, Python): every saved variable is in the environment when the app starts (process.env in Node, os.environ in Python). Server-only secrets belong here, without a public prefix.
The build can download packages but can't reach other services. Load data when a visitor opens the page, not while the app is being built.
Example: a mission with no build step
Both values are public, so they go straight into the page. Nothing here is secret.
<script src="https://cdn.jsdelivr.net/npm/@supabase/[email protected]/dist/umd/supabase.js"
integrity="sha384-A97u3Qnt9GZHURO9YJZRe7VQgGUeFzcv6I1oIGnUTxQrCxnpQMwR0/G8F2zt9abZ"
crossorigin="anonymous"></script>
<script type="module">
const client = window.supabase.createClient("https://your-project-ref.supabase.co", "your-anon-or-publishable-key");
const { data, error } = await client.from("notes").select("*");
document.body.textContent = error ? error.message : JSON.stringify(data);
</script>The script is pinned to one exact version, and the integrity hash makes the browser refuse the file if it is ever different. When you update, pin the new exact version and replace the integrity hash with the one for that file; keep both.
Example: a Next.js app
Set NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY on the Environment Variables screen. The first two are written into the browser files at build time. The service role key stays on the server and is read when a request comes in.
// lib/supabase.js: browser and server, public values only
import { createClient } from "@supabase/supabase-js";
export const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
);// app/api/notes/route.js: server only, runs on each request
import { createClient } from "@supabase/supabase-js";
export const dynamic = "force-dynamic";
export async function GET() {
const admin = createClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.SUPABASE_SERVICE_ROLE_KEY);
const { data, error } = await admin.from("notes").select("*");
if (error) return Response.json({ error: error.message }, { status: 500 });
return Response.json(data);
}With Vite the same browser code reads import.meta.env.VITE_SUPABASE_URL and import.meta.env.VITE_SUPABASE_ANON_KEY. A Vite app has no server of its own on moonbase, so it never uses the service role key.
Sign-in with Supabase Auth
If people sign in, add your mission's live address (and your custom domain, if you have one) to the redirect URLs in your Supabase project's authentication settings. Until you do, sign-in sends people back to the old address or shows an error.