> ## Documentation Index
> Fetch the complete documentation index at: https://docs.headlesscommerce.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 고객 인증

> Storefront API를 위한 JWT 토큰, 비회원 장바구니, 고객 신원 확인

# 고객 인증

고객 신원 확인이 필요한 Storefront 엔드포인트(`/customers/me`, `/orders`)에서는 JWT 토큰으로 인증합니다.

<Info>
  API 키 유형과 기본 인증에 대해서는 [소개](/ko/introduction#api-키-발급) 페이지를 참고하세요.
</Info>

## 고객 JWT 흐름

**Step 1.** 서버에서 Admin API를 사용하여 고객 토큰을 생성합니다:

```bash theme={null}
curl -X POST https://api.headlesscommerce.io/v1/admin/customers/{id}/token \
  -H "Authorization: Bearer sk_test_your_secret_key"
```

**Step 2.** 응답에 JWT 토큰이 포함됩니다:

```json theme={null}
{
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "expires_at": "2025-01-16T10:30:00Z"
}
```

**Step 3.** 클라이언트에서 `X-Customer-Token` 헤더로 이 토큰을 전달합니다:

```bash theme={null}
curl https://api.headlesscommerce.io/v1/storefront/customers/me \
  -H "Authorization: Bearer pk_test_your_key" \
  -H "X-Customer-Token: eyJhbGciOiJIUzI1NiIs..."
```

## 비회원 장바구니

장바구니는 고객 인증 없이 `session_id`로 생성할 수 있습니다:

```typescript theme={null}
const cart = await client.carts.create({
  session_id: 'guest-session-123',
});
```

비회원 고객이 로그인하면, 비회원 장바구니를 계정에 병합합니다:

```typescript theme={null}
// 고객 인증 후, 비회원 장바구니 병합
await client.carts.merge(guestCart.id, {
  customer_token: customerToken,
});
```

전체 구현 방법은 [장바구니 병합 레시피](/ko/guides/recipes#로그인-후-장바구니-병합)를 참고하세요.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.