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

환경 변수와 비밀 정보 관리

비밀 정보를 관리하고 공개 변수와 비공개 변수를 분리하며 클라이언트에 키가 노출되지 않도록 하여 여러 환경에서 SaaS를 안전하게 구성합니다.

환경 변수와 비밀 정보 관리은(는) CoddyKit의 무료 AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 AI Powered SaaS: Stripe + Auth + Billing + Deploy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

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.

자주 묻는 질문

“환경 변수와 비밀 정보 관리” 강의는 무료인가요?

네 — “환경 변수와 비밀 정보 관리” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의 전체를 잠금 해제할 수 있습니다. AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의에는 총 4개의 강의가 포함되어 있습니다.

“환경 변수와 비밀 정보 관리”에서 뭘 배우나요?

비밀 정보를 관리하고 공개 변수와 비공개 변수를 분리하며 클라이언트에 키가 노출되지 않도록 하여 여러 환경에서 SaaS를 안전하게 구성합니다. 브라우저에서 직접 실행하는 실습 코드로 AI Powered SaaS: Stripe + Auth + Billing + Deploy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

AI Powered SaaS: Stripe + Auth + Billing + Deploy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 AI Powered SaaS: Stripe + Auth + Billing + Deploy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“환경 변수와 비밀 정보 관리” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. SaaS와 인공지능 시너지 입문
  2. 기술 스택 선택
  3. 프로젝트 초기화 및 구조
  4. 환경 변수와 비밀 정보 관리
← AI Powered SaaS: Stripe + Auth + Billing + Deploy(으)로 돌아가기