# Your buyers

> Sign in with Eden for your own app. Buyers sign in with their Eden account, and one call tells you what they paid for. In private testing.

Let buyers sign in to your app with their Eden account, then check what they paid for with one
call. Eden handles the sign-in screen, the payment, and the access. Your app just asks. This is in
private testing and not open to every store yet.

## How it works

1. You make an app in your store and get a client id and secret.
2. Your app sends the buyer to Eden to sign in. They see your store's look, what your app will see,
   and a Continue button.
3. Eden sends them back to your app with a code. Your server swaps it for a token.
4. Your app calls `GET /v1/access?product=...` on each page load. Yes means show the content.

A buyer's sign-in from your app only ever reaches your own store's products. Your app never sees
their other purchases, their workspace, or their sign-in code.

## 1. Make your app

In Eden, open **Settings → API → Sign in with Eden** and click **New app**. Give it a name and the
addresses Eden should send buyers back to. Or make it with the store API:

```bash
curl -X POST https://api.eden.so/store-app/v1/sign-in-apps \
  -H "Authorization: Bearer $EDEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "My course app", "redirect_uris": ["https://myapp.com/auth/callback"]}'
```

The answer has `client_id` and `client_secret`. Eden shows the secret once, so save it in an
environment variable. Return addresses must start with `https://`, or `http://localhost` while you
build. A store can have 20 apps.

| Call                                     | What it does                         |
| ---------------------------------------- | ------------------------------------ |
| `GET /store-app/v1/sign-in-apps`         | Your store's apps                    |
| `POST /store-app/v1/sign-in-apps`        | Make one (secret shown once)         |
| `PATCH /store-app/v1/sign-in-apps/{id}`  | Rename it or change return addresses |
| `DELETE /store-app/v1/sign-in-apps/{id}` | Turn it off. No new sign-ins         |

## Add the tool to your product

Open the product in Eden. Under **What buyers get**, click **Tools**, then open the **Tools** row.
Paste your tool's link, then under **Advanced** pick the sign-in app you just made. The name is
the tab buyers see in the product, with an **Open** button. Add more tools the same way. Each gets
its own tab. Or send the whole list with the store API:

```bash
curl -X PATCH https://api.eden.so/store-app/v1/products/$PRODUCT_ID \
  -H "Authorization: Bearer $EDEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"tools": [{"name": "Hook Writer", "url": "https://mytool.com", "pitch": "Writes hooks in your voice.", "client_id": "eden_app_..."}]}'
```

Up to 6 tools per product. To change one, send the list again with each tool's `id` from
`GET /store-app/v1/products/{id}`. A tool sent without an `id` is a new tab. A tool with no `url`
is a draft only you see. `[]` takes them all away.

### Or let Eden host it

Send a zip of the built tool (the `dist` folder). Each upload is a new version at its own private
preview address (`previewUrl`). Buyers keep the live version until you make the new one live. Add
`?live=1` to skip the preview. The last 10 versions are kept, and going back is one call. The
first version you make live sets the tool's address, `https://<name>.<tool domain>/`.

```bash
cd dist && zip -r ../tool.zip . && cd ..
curl -X POST https://api.eden.so/store-app/v1/products/$PRODUCT_ID/tools/$TOOL_ID/deploy \
  -H "Authorization: Bearer $EDEN_API_KEY" \
  -H "Content-Type: application/zip" \
  --data-binary @tool.zip
```

| Call                                                                | What it does                                               |
| ------------------------------------------------------------------- | ---------------------------------------------------------- |
| `POST /store-app/v1/products/{id}/tools/{toolId}/deploy`            | Upload a zip, 25 MB at most. A private preview             |
| `GET /store-app/v1/products/{id}/tools/{toolId}/versions`           | The address and the last 10 uploads, each with its preview |
| `POST /store-app/v1/products/{id}/tools/{toolId}/versions/{v}/live` | Make one live: a new one, or an old one to go back         |

The tool's address becomes its `url`, and Eden lets its sign-in app return there and to the newest
preview.

### While you build

Run the tool on your computer (`npm run dev`) and sign in with your own Eden account. Return
addresses on `localhost` match on any port, so it still works when Vite moves to 5174. You own the
product, so `GET /v1/access` always answers yes for you, with `"source": "owner"`.

### Or let Eden set it up

`POST /store-app/v1/products/{id}/tools/new/prompt` with `{"name", "idea", "starter"}` adds a
draft tool, makes a public sign-in app for it (no secret), and answers a `prompt` to paste into an
AI that builds apps. Use a tool's `id` instead of `new` to get its prompt again. When you save the
tool's live `url`, Eden adds its address to that sign-in app for you.

## 2. Send the buyer to sign in

Standard OAuth with PKCE. Make a random `code_verifier`, keep it, and send its SHA-256 as the
challenge.

```text
https://oauth.eden.so/oauth/authorize
  ?client_id=eden_app_...
  &redirect_uri=https://myapp.com/auth/callback
  &response_type=code
  &scope=identity purchases email
  &code_challenge=...
  &code_challenge_method=S256
  &state=...
```

| Scope       | What your app sees                                                |
| ----------- | ----------------------------------------------------------------- |
| `identity`  | Their id, name, and photo. Always included                        |
| `purchases` | What they bought from your store, and the access check            |
| `email`     | Their email, only if they leave "Share my email address" ticked   |
| `social`    | Search posts, read transcripts, and look up creators as the buyer |
| `ai`        | Eden's AI writing, as the buyer                                   |
| `data`      | Your app's own saved data for this buyer                          |

These scopes can't be mixed with `read` or `write`. Your app can never reach the buyer's Eden
workspace: no boards, notes, or saves.

## 3. Swap the code for a token

```bash
curl -X POST https://oauth.eden.so/oauth/token \
  -d grant_type=authorization_code \
  -d client_id=eden_app_... \
  -d client_secret=$EDEN_APP_SECRET \
  -d code=... \
  -d redirect_uri=https://myapp.com/auth/callback \
  -d code_verifier=...
```

You get an `access_token` (one hour) and a `refresh_token` (30 days). Refresh with
`grant_type=refresh_token`. Do this on your server, never in the browser.

A tool with no server of its own uses a public sign-in app (the kind Eden makes for **Copy
prompt**). It sends no `client_secret`, only the `code_verifier`, and can make this call from the
browser.

## 4. Check access

```bash
curl "https://api.eden.so/v1/access?product=PRODUCT_ID" \
  -H "Authorization: Bearer $BUYER_TOKEN"
```

```json
{
  "ok": true,
  "product_id": "PRODUCT_ID",
  "product_name": "The Writing Course",
  "access": true,
  "source": "purchase",
  "billing": "subscription",
  "interval": "month",
  "price_name": "Monthly",
  "status": "renews",
  "ends_at": null,
  "renews_at": "2026-12-21T00:00:00.000Z"
}
```

- `access` is the only field you need to gate content.
- `status` is `active`, `renews`, `past_due`, `ends`, or `trial`. `past_due` still has access while
  the payment is retried.
- Refunds, removed access, and passed end dates all answer `access: false`.
- Answers are kept for 30 seconds, so it's fine to call on every page load.
- A product from another store answers 404.
- `source` is `purchase`, `grant`, or `owner`. `owner` is you, signed in to your own app, so you can
  try it like a buyer.

## The other buyer calls

| Call                   | What it does                                            | Scope       |
| ---------------------- | ------------------------------------------------------- | ----------- |
| `GET /v1/me`           | The buyer: id, name, photo, and email if they shared it | `identity`  |
| `GET /v1/me/purchases` | Everything they can open from your store right now      | `purchases` |
| `GET /v1/access`       | Yes or no for one product, the plan, and when it ends   | `purchases` |

## Use Eden from your app

Ask for `social`, `ai`, and `data` when the buyer signs in, and your app can use Eden's own abilities
with the same buyer token. AI and social calls use the buyer's Eden credits. You can include credits
with your product (**Credits for buyers** on its Tools tab), and buyers can buy more in Eden.

| Call                                   | What it does                                                                                                     | Scope    | Cost       |
| -------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | -------- | ---------- |
| `POST /v1/ai`                          | `{"prompt", "system", "max_words"}` answers `{"text"}`. Add `"custom_ai_id"` to answer as one of your Custom AIs | `ai`     | 1 credit   |
| `GET /v1/posts/search?q=`              | Top posts on a topic, ranked against each creator's normal                                                       | `social` | 0.1 credit |
| `GET /v1/transcripts?url=`             | The transcript of a YouTube, Instagram, or TikTok link (202 while it's fetched)                                  | `social` | 0.1 credit |
| `GET /v1/creators/search?q=`           | Creators in a niche                                                                                              | `social` | 0.1 credit |
| `GET /v1/creators/{platform}/{handle}` | One creator and their top posts                                                                                  | `social` | 0.1 credit |
| `PUT /v1/data/{key}`                   | Save `{"value": ...}`, 256 KB each, 100 keys per buyer                                                           | `data`   | Free       |
| `GET /v1/data/{key}`, `GET /v1/data`   | Read one, or list the keys                                                                                       | `data`   | Free       |
| `DELETE /v1/data/{key}`                | Remove one                                                                                                       | `data`   | Free       |

```bash
curl -X POST https://api.eden.so/v1/ai \
  -H "Authorization: Bearer $BUYER_TOKEN" -H "Content-Type: application/json" \
  -d '{"prompt":"Score this hook from 1 to 10 and give 3 stronger versions: I quit my job","max_words":200}'
```

- Failed calls and empty results are free. AI is charged only after it answers.
- Out of credits answers `402` with `add_credits_url`. Send the buyer there to get more.
- Saved data belongs to your app and the buyer. Another app can't read it, and neither can you from
  the store API.
- A call your app didn't ask for at sign-in answers `403`.

## The sign-in screen

The screen your buyers see wears your store's look: your colors, fonts, background, and buttons.
Change your store's look in Eden and the screen follows. The part that says what your app will see,
and the Continue button, is always Eden's, so buyers can trust it on every store.

## Coming next

| Call                            | What it does                                |
| ------------------------------- | ------------------------------------------- |
| `GET /v1/courses/{id}`          | Modules and lessons they can open           |
| `GET /v1/lessons/{id}`          | Lesson content and a short-lived video link |
| `PUT /v1/lessons/{id}/progress` | Viewed, completed, and an optional score    |
| `GET /v1/courses/{id}/progress` | Where they are in the course                |
