0Pricing
AI Powered SaaS: Stripe + Auth + Billing + Deploy · Pelajaran

Variabel Lingkungan dan Pengelolaan Rahasia

Konfigurasikan SaaS Anda dengan aman di berbagai lingkungan dengan mengelola rahasia, memisahkan variabel publik dan privat, serta mencegah kunci bocor ke klien.

Variabel Lingkungan dan Pengelolaan Rahasia adalah pelajaran AI Powered SaaS: Stripe + Auth + Billing + Deploy gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar AI Powered SaaS: Stripe + Auth + Billing + Deploy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus AI Powered SaaS: Stripe + Auth + Billing + Deploy mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Why Configuration Matters

A SaaS connects to databases, payment providers, and AI APIs — each with keys that differ per environment. Environment variables keep them out of code so one codebase runs anywhere.

The .env File

Local config lives in a .env file as plain key-value pairs. It's loaded at startup and must never be committed to git.

DATABASE_URL=postgresql://localhost/app
STRIPE_SECRET_KEY=sk_test_123
OPENAI_API_KEY=sk-abc

Never Commit Secrets

Never commit secrets: add .env to .gitignore and ship a .env.example with empty values, so teammates know what to fill in without seeing real keys.

# .gitignore
.env
.env.local

Public vs Private Variables

In Next.js, only variables prefixed NEXT_PUBLIC_ reach the browser bundle — everything else stays server-only. Never prefix a real secret, or every visitor sees it.

NEXT_PUBLIC_APP_URL=https://app.com   # safe in browser
STRIPE_SECRET_KEY=sk_live_xxx          # server only

Reading Variables

Read variables through process.env. Server code can access any of them; client code only ever sees the public, NEXT_PUBLIC_ ones.

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
const url = process.env.NEXT_PUBLIC_APP_URL;

Validating Env at Startup

A missing key should fail fast, not at 2am in production. Validate required variables on boot with a schema like Zod so problems surface immediately.

import { z } from 'zod';
const env = z.object({
  DATABASE_URL: z.string().url(),
  STRIPE_SECRET_KEY: z.string().min(1)
}).parse(process.env);

Per-Environment Files

Next.js loads .env.local, then .env.development or .env.production. These per-environment files keep different values cleanly separated.

Secrets in Hosting Platforms

In production you don't ship a .env file. Set variables in your host's dashboard — Vercel, Render — so they're injected securely at runtime.

vercel env add STRIPE_SECRET_KEY production

Rotating Keys

If a key leaks, rotate it: generate a new one, update your env store, redeploy. Because keys live outside code, rotation is quick and low-risk.

Avoiding Common Leaks

Watch for common leaks: logging full process.env, returning secrets in API responses, hardcoding keys as fallbacks, or committing a real .env.

Best Practices

Best practices: keep secrets in .env and out of git, expose only truly public values with NEXT_PUBLIC_, validate at startup, and store prod secrets in your host.

Quick Check

Test your secrets knowledge.

Recap

Recap: store config in .env and keep it out of git, use NEXT_PUBLIC_ only for safe values, validate at startup, and set prod secrets in your host.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Variabel Lingkungan dan Pengelolaan Rahasia” gratis?

Ya — teks lengkap “Variabel Lingkungan dan Pengelolaan Rahasia” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus AI Powered SaaS: Stripe + Auth + Billing + Deploy, upgrade ke CoddyKit PRO. Kursus AI Powered SaaS: Stripe + Auth + Billing + Deploy mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Variabel Lingkungan dan Pengelolaan Rahasia”?

Konfigurasikan SaaS Anda dengan aman di berbagai lingkungan dengan mengelola rahasia, memisahkan variabel publik dan privat, serta mencegah kunci bocor ke klien. Kamu berlatih AI Powered SaaS: Stripe + Auth + Billing + Deploy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai AI Powered SaaS: Stripe + Auth + Billing + Deploy?

Tidak diperlukan pengalaman sebelumnya. AI Powered SaaS: Stripe + Auth + Billing + Deploy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.

Berapa lama pelajaran “Variabel Lingkungan dan Pengelolaan Rahasia” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran AI Powered SaaS: Stripe + Auth + Billing + Deploy ini?

Ya. Setiap pelajaran AI Powered SaaS: Stripe + Auth + Billing + Deploy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Pengantar Sinergi SaaS dan Kecerdasan Buatan
  2. Memilih Tumpukan Teknologi
  3. Inisialisasi & Struktur Proyek
  4. Variabel Lingkungan dan Pengelolaan Rahasia
← Kembali ke AI Powered SaaS: Stripe + Auth + Billing + Deploy