0
0
Supabasecloud~10 mins

Environment management in Supabase - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Environment management
Start: Define environments
Create environment variables
Assign variables to environment
Deploy application
Application reads env variables
Use different env for dev, test, prod
Update env variables as needed
Redeploy or refresh app to apply changes
This flow shows how environment variables are defined, assigned, and used in Supabase projects to manage different settings for development, testing, and production.
Execution Sample
Supabase
1. Define SUPABASE_URL and SUPABASE_KEY
2. Set them in Supabase project settings
3. Deploy app referencing these variables
4. App reads variables at runtime
5. Change variables for different environments
This sample shows the steps to manage environment variables in Supabase for different deployment stages.
Process Table
StepActionEnvironment VariableValue SetEffect on App
1Define variableSUPABASE_URLhttps://xyz.supabase.coApp will connect to this URL
2Define variableSUPABASE_KEYpublic-anonymous-keyApp will authenticate with this key
3Assign variablesSUPABASE_URL & SUPABASE_KEYSet in Supabase project settingsVariables available to app at runtime
4Deploy appN/AUses assigned env variablesApp connects to correct Supabase instance
5App runtimeReads SUPABASE_URLhttps://xyz.supabase.coConnects to database
6App runtimeReads SUPABASE_KEYpublic-anonymous-keyAuthenticates requests
7Change env for prodSUPABASE_URLhttps://prod.supabase.coApp connects to production DB
8Redeploy appN/AUses new env variablesApp uses updated environment
9ExitN/AN/AEnvironment management complete
💡 All environment variables set and app deployed with correct environment settings
Status Tracker
VariableStartAfter Step 1After Step 3After Step 7Final
SUPABASE_URLundefinedhttps://xyz.supabase.cohttps://xyz.supabase.cohttps://prod.supabase.cohttps://prod.supabase.co
SUPABASE_KEYundefinedpublic-anonymous-keypublic-anonymous-keypublic-anonymous-keypublic-anonymous-key
Key Moments - 2 Insights
Why do we set environment variables in the project settings instead of hardcoding them?
Setting variables in project settings keeps sensitive info secure and allows easy changes without modifying code, as shown in steps 2 and 3 of the execution_table.
What happens if we forget to redeploy the app after changing environment variables?
The app will keep using old variables until redeployed, so changes in step 7 won't take effect until step 8, as seen in the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of SUPABASE_URL after step 3?
Ahttps://xyz.supabase.co
Bundefined
Chttps://prod.supabase.co
Dpublic-anonymous-key
💡 Hint
Check the 'Value Set' column at step 3 in the execution_table
At which step does the app start using the production database URL?
AStep 4
BStep 7
CStep 8
DStep 5
💡 Hint
Look for when the app redeploys with new environment variables in the execution_table
If SUPABASE_KEY was changed to a new key at step 7 but the app was not redeployed, what would happen?
AApp uses new key immediately
BApp continues using old key
CApp crashes
DApp ignores the key
💡 Hint
Refer to key moment about redeploying after env changes and execution_table steps 7 and 8
Concept Snapshot
Environment management in Supabase:
- Define variables like SUPABASE_URL and SUPABASE_KEY
- Set them securely in project settings
- Deploy app referencing these variables
- Use different variables for dev, test, prod
- Redeploy app to apply changes
- Keeps config secure and flexible
Full Transcript
Environment management in Supabase involves defining environment variables such as SUPABASE_URL and SUPABASE_KEY. These variables are set securely in the project settings, not hardcoded in the app. When the app is deployed, it reads these variables at runtime to connect and authenticate with the correct Supabase instance. Different environments like development and production use different variable values. After changing environment variables, the app must be redeployed to apply the new settings. This process keeps sensitive information secure and allows easy configuration changes without modifying the app code.