• Blog
  • Documentation
  • Courses
  • Changelog
  • AI Starters
  • UI Kit
  • FAQ
  • Supamode
    New
  • Pricing

Launch your next SaaS in record time with Makerkit, a React SaaS Boilerplate for Next.js and Supabase.

Makerkit is a product of Makerkit Pte Ltd (registered in the Republic of Singapore)Company Registration No: 202407149CFor support or inquiries, please contact us

About
  • FAQ
  • Contact
  • Verify your Discord
  • Consultation
  • Open Source
  • Become an Affiliate
Product
  • Documentation
  • Blog
  • Changelog
  • UI Blocks
  • Figma UI Kit
  • AI SaaS Starters
License
  • Activate License
  • Upgrade License
  • Invite Member
Legal
  • Terms of License
  • Global Configuration
    • Environment Variables
    • Feature Flags
  • Server Actions
    • Sending CSRF Token to Actions
    • Server Actions Error Handling
  • The Makerkit SDK
    • User SDK
    • Organization SDK
    • Organization Subscription SDK
    • Data Loader SDK
  • Architecture and Folder Structure
    • Structure your Application
    • Data Model
    • Adding API Routes
    • Change Authentication strategy
    • Fetching the signed in User
    • Reading Records from Postgres
    • Creating a Record
    • Seeding Local Data
    • Introduction
    • Configuring Plans
    • Project Configuration
    • Updating the Navigation menu
    • Adding a new translation string
    • Supabase is not starting
    • Calling API Routes from the client
    • Adding Pages
    • Updating the Sidebar menu
    • Setup oAuth
    • Fetching the selected Organization
    • Resetting the local DB
    • Running the Stripe Webhook locally
    • Branding
    • Setting a Default Language
    • Supabase is not stopping
    • Dark Theme
    • Theming
    • API Routes vs Server Actions
    • Generating Database Types
    • Updating the Logo
    • Adding a new language in the Next.js Supabase SaaS Kit
    • Tables/Functions not found
    • Updating the Fonts
    • Adding Pages
    • Adding a new translation file
    • Contentlayer gets stuck
    • Guarding Pages
    • Using Lemon Squeezy instead of Stripe
    • Updating the Favicons
    • Using the Language Switcher
    • Dynamic server usage error
    • Environment variables
    • Detect current Locale
    • 403 error with API/Actions
    • Setting up Emails
This documentation is for a legacy version of Next.js and Supabase. For the latest version, please visit the Next.js and Supabase V2 documentation

Understanding and setting the environment variables in your Next.js Supabase project

Learn how to set environment variables in your Next.js Supabase project and how to use them in your code.

Makerkit ships with some environment variables pre-configured for you.

If you don't have experience with environment variables, you can think of them as a way to store configuration values for your project.

Here are the types of environment variables you can use in your Next.js project:

  1. .env: This file is used to store environment variables that are common to all environments (development, staging, production). Only use it for public and shared variables.
  2. .env.local: This file is used to store environment variables that are specific to your local development environment. Do not commit this file to your repository (this is already ignored by the kit's defaults).
  3. .env.development: This file is used to store environment variables that are specific to your development environment. As long as you don't use it for sensitive data, you can commit this file to your repository.
  4. .env.production: This file is used to store environment variables that are specific to your production environment. Do not add sensitive data to this file. Instead, use your CI provider.

If I set mt variables in Vercel/another hosting provider, do I still need to set them in my project?

No. If you set your environment variables in your hosting provider, you don't need to set them in your project.

Can I add secrets to my environment variables, like my OpenAI API key?

No. You should never add secrets to your environment variables. Instead, you should use your CI provider to set them.

Does Next.js automatically load my environment variables?

Yes, Next.js automatically loads your environment variables. You can access them in your code using process.env.VARIABLE_NAME.

I added a variable to my .env file, but I can't access it in my code. What's wrong?

Next.js only loads environment variables that start with NEXT_PUBLIC_ if you are trying to access them from your client-side. If you want to access a variable in your client code, you need to prefix it with NEXT_PUBLIC_. Note: never add secrets to your client-side code, therefore do not prefix them with NEXT_PUBLIC_ if it's private data.

On this page
  1. If I set mt variables in Vercel/another hosting provider, do I still need to set them in my project?
    1. Can I add secrets to my environment variables, like my OpenAI API key?
      1. Does Next.js automatically load my environment variables?
        1. I added a variable to my .env file, but I can't access it in my code. What's wrong?