0
0
Supabasecloud~10 mins

Environment variables and secrets in Supabase - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Environment variables and secrets
Start: Deploy Supabase Project
Set Environment Variables
Set Secrets (Sensitive Data)
Supabase Reads Variables & Secrets
Use Variables in Functions/Configs
Run Project with Secure Config
End
This flow shows how you set environment variables and secrets in Supabase, which the system then uses securely during project execution.
Execution Sample
Supabase
SUPABASE_URL=https://xyz.supabase.co
SUPABASE_ANON_KEY=anon-key-123

// Use in function:
const url = Deno.env.get('SUPABASE_URL');
This code sets environment variables for Supabase URL and anon key, then accesses the URL in code securely.
Process Table
StepActionVariable/Secret SetValueEffect
1Deploy Supabase projectNoneNoneProject created, ready for config
2Set environment variable SUPABASE_URLSUPABASE_URLhttps://xyz.supabase.coURL stored for project use
3Set secret SUPABASE_ANON_KEYSUPABASE_ANON_KEYanon-key-123Secret stored securely, hidden from logs
4Supabase reads variablesSUPABASE_URLhttps://xyz.supabase.coVariable available to runtime
5Supabase reads secretsSUPABASE_ANON_KEYanon-key-123Secret available securely to runtime
6Code accesses SUPABASE_URLSUPABASE_URLhttps://xyz.supabase.coCode uses URL to connect to Supabase
7Code accesses SUPABASE_ANON_KEYSUPABASE_ANON_KEYanon-key-123Code uses anon key for authentication
8Run projectNoneNoneProject runs with secure config
9ExitNoneNoneAll variables and secrets used securely
💡 All environment variables and secrets set and used securely; project runs with correct config
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
SUPABASE_URLundefinedhttps://xyz.supabase.cohttps://xyz.supabase.cohttps://xyz.supabase.cohttps://xyz.supabase.cohttps://xyz.supabase.co
SUPABASE_ANON_KEYundefinedundefinedanon-key-123anon-key-123anon-key-123anon-key-123
Key Moments - 3 Insights
Why do we set environment variables separately from secrets?
Environment variables like URLs are less sensitive and can be visible in some logs, but secrets like keys must be stored securely and hidden from logs, as shown in steps 2 and 3 of the execution_table.
How does the code access these variables safely?
The code accesses variables via Deno.env.get('VAR_NAME'), which reads the secure environment at runtime, ensuring secrets are not hardcoded, as shown in steps 6 and 7.
What happens if a secret is missing?
If a secret is missing, the project may fail to authenticate or connect properly, causing errors at runtime, which would be evident if the value is undefined in the variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3. What is the value of SUPABASE_ANON_KEY?
Ahttps://xyz.supabase.co
Bundefined
Canon-key-123
Dnull
💡 Hint
Check the 'Variable/Secret Set' and 'Value' columns at step 3 in execution_table.
At which step does the code first access the SUPABASE_URL variable?
AStep 4
BStep 6
CStep 2
DStep 8
💡 Hint
Look for 'Code accesses SUPABASE_URL' in the Action column of execution_table.
If SUPABASE_ANON_KEY was not set at step 3, what would be its value at step 7?
Aundefined
Banon-key-123
Cnull
Dempty string
💡 Hint
Refer to variable_tracker to see how missing secrets appear as undefined.
Concept Snapshot
Environment variables store configuration like URLs.
Secrets store sensitive data like keys securely.
Set them in Supabase dashboard or CLI.
Access in code via Deno.env.get('VARIABLE_NAME').
Secrets are hidden from logs and safe at runtime.
Always keep secrets out of code files.
Full Transcript
This lesson shows how environment variables and secrets work in Supabase. First, you deploy your project. Then you set environment variables like SUPABASE_URL and secrets like SUPABASE_ANON_KEY. Supabase reads these securely at runtime. Your code accesses them using Deno.env.get(). This keeps sensitive data safe and your project configured correctly. The execution table traces each step from setting variables to running the project. The variable tracker shows how values change. Key moments clarify why secrets are separate and how code uses them. The quiz tests your understanding of these steps and values.