---
title: "Auth, roles & API keys"
description: "How EdgeCart authenticates admins, storefronts, and API clients."
---

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

# Auth, roles & API keys

EdgeCart uses Better Auth for people and two API-key styles for programmatic
access. The three paths have different credentials and scopes.

## Admin sessions

Admins sign in with email and password. The browser keeps a Better Auth session
cookie, and every Admin API request sends:

- the session cookie, and
- the `x-store-id` header.

A request for a store the member does not belong to returns `404`, not `403`.

Roles:

| Role | Intended access |
|---|---|
| `owner` | Full store control, including settings and membership. |
| `admin` | Full store administration. |
| `member` | Day-to-day store operations. |
| `viewer` | Read-only access. |

## Storefront and customer access

- The storefront first calls the key-free `GET /api/storefront-config` to get
  the publishable key and store profile.
- Keyed storefront requests send `x-publishable-api-key`.
- Customer account routes also require the customer's session cookie.

The publishable key (`pk_...`) is public by design. Secret keys stay on the
server; EdgeCart stores only their hash.

## Creating API keys

API keys are managed through the Admin API (`/api/api-keys`). A key is either
`publishable` or `secret`. Publishable keys are safe for browsers; secret keys
must never be shipped to a client.

> **Social login is not wired**
>
> GitHub and Google variables exist in the example environment, but the runtime
> auth configuration only enables email/password. Do not document or rely on
> social login yet. See [current limitations](https://edgecart.dev/reference/limitations).

## CSRF and idempotency

- Cookie-authenticated mutations check the request `Origin` against
  `TRUSTED_ORIGINS`.
- Mutation requests accept an `Idempotency-Key` header. Reuse the same key when
  retrying the same request.
- Keys are scoped per store; a key reused with a different body is rejected.

## Related

- [API conventions](https://edgecart.dev/reference/api-conventions)
- [Admin API guide](https://edgecart.dev/developers/admin-api)
- [Storefront API guide](https://edgecart.dev/developers/storefront-api)
- [Configuration & secrets](https://edgecart.dev/developers/configuration)

Source: https://edgecart.dev/developers/auth/index.mdx
