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

# Embed the app

> Show an app inside your platform, already signed in as the person looking at it.

You can show an app inside your platform in an iframe. If the app asks people to sign in, they see its sign-in page inside the frame. To skip that and open the app already signed in as the end user, your server can create a one-time sign-in token and add it to the iframe URL. The app itself doesn't need any changes.

## Decide if you need a token

You need a sign-in token only when the app asks people to sign in. That depends on the app's visibility, which you set with `public_settings` when you [create the app](https://docs.base44.com/api-reference/create-app.md).

| Visibility API value | Shown in settings as | Needs a token |
| :- | :- | :- |
| `public_without_login` | **Public (no login)** | No |
| `public_with_login` | **Public (login required)** | Yes |
| `private_with_login` | **Private** | Yes |

If you don't need a token, load the app's address in the iframe. If you do, [mint one](#sign-the-end-user-in) for each end user so they skip the sign-in page.

> [!NOTE]
>
> An app with no login can't tell visitors apart, so features that depend on who someone is, such as profiles or data saved for each person, don't work. Learn more about [app visibility](https://docs.base44.com/Setting-up-your-app/Managing-access.md#setting-your-app-visibility).

## Let the app load in a frame

A new app refuses to load inside an iframe on another site: `prevent_iframe_embedding` defaults to `true`, and a clone or a remix starts that way too. Set it to `false` in the [Create app](https://docs.base44.com/api-reference/create-app.md) call when you plan to embed the app. For an app that already exists, including a remix, send `{ "prevent_iframe_embedding": false }` to [Update security headers](https://docs.base44.com/api-reference/update-security-headers.md), which applies to the published app right away. Preview URLs aren't affected by the setting.

> [!WARNING]
>
> A remix copies the source app in the background and, when it finishes, writes the source's `public_settings` and `custom_instructions` over anything you set in the meantime. Poll [Get app](https://docs.base44.com/api-reference/get-app.md) until `status.state` is no longer `processing` before you configure a remix, then read the settings back.

## Give the app your platform's data

An app your builders create often needs data that only your platform holds, under your platform's permissions. Two patterns work, and both are things your platform builds around the frame rather than Base44 features:

* **The host page answers the app's requests.** The app asks the page that frames it over `postMessage`, and the page answers from its own session. The app holds no credential, and the identity is whoever is signed in to your platform. The reference integration does this: it mints a short-lived viewer token for the current user and posts it into the frame when the app asks. The app then works only inside your page.
* **The host issues a short-lived signed token.** Your platform issues a token scoped to that app and the queries you granted it, and the app calls your platform's API directly. The request carries no Base44 session for the person using the app, so anything inside Base44 that is per user, such as a connector that user connected, can't resolve for it.

In both cases, say in the app's [custom instructions](https://docs.base44.com/developers/white-label/custom-instructions.md#connect-back-to-your-platform) how the app gets its data and what's read-only.

## Sign the end user in

Your server signs an end user in with two calls. The first gives them access to the app, and the second returns the app's address with a sign-in token on it. Then you load that address in your iframe.

> [!TIP]
>
> **Before you begin:** Use the [personal access token](https://docs.base44.com/developers/white-label/tenancy-and-credentials.md#authenticating-as-the-integration-account) your integration already builds with. Send it from your server as `Authorization: Bearer <token>`, together with `X-Active-Workspace-Id: <workspace id>`.

If your plan includes [workspace API keys](https://docs.base44.com/Enterprise/workspace-secrets.md), you can use one instead. Create one in your integration's workspace and send it as `api_key: <key>`, together with `X-Active-Workspace-Id: <workspace id>`. Give it:

* **Permissions:** **Provision app users** and **Mint embed sign-in tokens**.
* **App access:** **All current and future apps**, since your builders keep creating new ones.

**1. Provision the end user**

Send `POST /api/apps/{app_id}/users/provisions` with the end user's email and a role. Apps have `admin` and `user` roles by default, and you can [add your own](https://docs.base44.com/Setting-up-your-app/Managing-access.md#choosing-your-users-roles):

```json theme={null}
{ "email": "dana@example.com", "role": "user" }
```

This gives them access to the app. It's idempotent, so you can call it before every mint. The response returns the end user's `email` and `role`, and a `status` that is `created` the first time and `exists` after that. If the end user already existed, `role` is the role they already had.

> [!WARNING]
>
> Take the email from your own server-side session, never from a value the browser sends. The token signs in whichever email you send, so if that email comes from the browser, an end user could send someone else's and open the app as them.

**2. Mint a sign-in token**

Send `POST /api/apps/{app_id}/embed-url` with the same email and a `target`, which is the version of the app you want to show:

```json theme={null}
{ "email": "dana@example.com", "target": "latest_preview" }
```

| Target value | What it shows |
| :- | :- |
| `live_site` | The published app. This is the default, and it needs the app to be published. |
| `latest_preview` | The latest built version, including changes you haven't published. |
| `live_preview` | The app's running sandbox, which shows each change while the agent builds. |

The response returns three fields:

* **`embed_url`:** The address of that version with the token already on it. For `latest_preview` and `live_preview`, it can also carry a one-time preview token, so use it exactly as returned.
* **`token`:** The sign-in token on its own. It's already on `embed_url`, so you don't need to send it anywhere.
* **`expires_in`:** How many seconds the token lasts, which is 60.

A `live_preview` mint also starts the app's sandbox if it isn't running, and `embed_url` shows a loading page until it is.

**3. Load the URL in your iframe**

Set the iframe's `src` to `embed_url`, and the app opens signed in as the end user. A token lasts 60 seconds and works only once, so mint a new one each time you load the frame.

> [!NOTE]
>
> **When the published app won't load in your iframe:** If your workspace has an [embedding policy](https://docs.base44.com/Enterprise/Enterprise-SSO-and-app-visibility.md#controlling-app-embedding) set to **Only these sites**, add your platform's website to its list. With **No one**, no website can embed your published apps. The policy applies only to `live_site`, so preview targets aren't affected.

> [!TIP]
>
> The reference integration does all three steps in [`embedSession.ts`](https://github.com/base44/base44-platform-starter/blob/main/src/lib/embedSession.ts), using a workspace API key.

## Errors

If a call fails, the response includes an error with a `code`, a `message`, and `details`. Use the `code` to tell what went wrong. These are the errors minting a token can return.

| Status | Error code | What it means |
| :- | :- | :- |
| `400` | `app_not_deployed` | You asked for `live_site`, and the app isn't published. |
| `400` | `app_has_no_slug` | The app doesn't have an address yet. |
| `403` | `privileged_user` | The email belongs to a service account, or to the app's owner or an editor and the request used someone else's token. The owner and editors can be signed in only with a workspace API key, or with their own personal access token. |
| `404` | `unknown_user` | The email isn't provisioned for this app. |

### When the app opens signed out

If the sign-in token can't be used, the app still loads in your iframe, but signed out, with no error. A private app then shows its sign-in page. Check these causes:

* **The token expired or was already used.** Tokens last 60 seconds and work once, so the frame has to load soon after you mint.
* **Too many sign-ins.** Each app accepts up to 60 embedded sign-ins a minute.
* **The app [requires MFA](https://docs.base44.com/Setting-up-your-app/Managing-login-and-registration.md#requiring-mfa).** Embedded sign-in doesn't work for an app that requires multi-factor authentication.

## See also

* [The build turn](https://docs.base44.com/developers/white-label/the-build-turn.md): Create, preview, and publish the app you're embedding
* [Tenancy and credentials](https://docs.base44.com/developers/white-label/tenancy-and-credentials.md): The account that owns your builders' apps, and the token that creates them
* [Workspace secrets](https://docs.base44.com/Enterprise/workspace-secrets.md): Create and manage a workspace API key for embedding
* [Controlling app embedding](https://docs.base44.com/Enterprise/Enterprise-SSO-and-app-visibility.md#controlling-app-embedding): Choose which websites can embed the apps in your workspace


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