# Environment Variables Guide

This document explains how to use environment variables in the front app.

## Setup

1. Copy the `.env.example` file to `.env.local`:
   ```bash
   cp .env.example .env.local
   ```

2. Update the values in `.env.local` with your actual configuration.

3. **Important**: Get your Strapi API token:
   - Go to your Strapi admin panel (default: http://localhost:1337/admin)
   - Navigate to Settings → API Tokens
   - Create a new API token with appropriate permissions
   - Copy the token and add it to your `.env.local` file

## Environment Variables

### Public Variables (Browser-accessible)

Variables prefixed with `NEXT_PUBLIC_` are exposed to the browser:

- `NEXT_PUBLIC_API_URL` - The URL of the backend API (Strapi) - Default: `http://localhost:1337`
- `NEXT_PUBLIC_SITE_URL` - The URL of the frontend application - Default: `http://localhost:3000`
- `NEXT_PUBLIC_STRAPI_TOKEN` - Strapi API token for authentication - **Required**

### Server-side Variables

Variables without the `NEXT_PUBLIC_` prefix are only available on the server:

- Add any server-side only variables here (API keys, secrets, etc.)

## Usage

### Using environment variables in your code:

```typescript
import { env } from '@/lib/env';

// In any component or page
console.log(env.apiUrl);
console.log(env.siteUrl);
```

### For server-side only variables:

```typescript
import { serverEnv } from '@/lib/env';

// Only in server components or API routes
console.log(serverEnv.apiSecretKey);
```

## Important Notes

1. **Never commit `.env.local`** - It contains sensitive information
2. **Always commit `.env.example`** - It serves as a template for other developers
3. **Restart the dev server** - After changing environment variables, restart `npm run dev`
4. **Public variables are bundled** - `NEXT_PUBLIC_*` variables are embedded in the client bundle

## Files

- `.env.local` - Your local environment variables (gitignored)
- `.env.example` - Template for environment variables (committed to git)
- `src/lib/env.ts` - Type-safe environment variable access helper

