# Publishable keys

URL: https://docs.folkways.io/docs/console/publishable-keys

Let a public, read-only app connect without a backend, with a key it trades for anonymous tokens.

A **publishable key** lets an app with no backend, such as a public scoreboard or a status page, connect to Folkways.
The app trades the key for an **anonymous, read-only token** and connects with that. The key ships inside your app,
so everything it grants is public.

| A publishable key can | It can't |
| --- | --- |
| Grant `subscribe` (and `history`) on the topics you choose | Publish, set values or send signals |
| Issue anonymous tokens, up to 15 minutes each | Name a user |

If users sign in to your app, use a [signing key](/docs/console/signing-keys) and tokens from your backend instead.

## Create one [#create-one]

1. In the segment's **Settings**, turn on **Allow anonymous connections**. Without it, the key's tokens are refused.
2. On **Publishable keys**, choose **Add key**.
3. Name it, e.g. "Public scoreboard", and set **What it may read**: topic patterns such as `scores/>`.
4. Optionally set an expiry date. After it, the key stops working and no token it issued outlives it.
5. Save and copy the key into your app.

## Pause, resume and revoke [#pause-resume-and-revoke]

| Action | Effect |
| --- | --- |
| **Pause** | New exchanges are refused with `Suspended`, and connections using the key's tokens close within about a minute. **Resume** undoes it |
| **Revoke** | The key stops working for good (`AuthInvalid`), and its connections close within about a minute |

To rotate a key: create a new one, ship your app with it, then revoke the old one.

## Use it [#use-it]

<Tabs items={['JavaScript', 'HTTP']}>
  <Tab value="JavaScript">
    ```ts
    const client = new Folkways.Realtime({ url: 'https://realtime.folkways.net', publishableKey: PUBLISHABLE_KEY });
    ```
  </Tab>
  <Tab value="HTTP">
    Exchange it at [`POST /v1/token`](/docs/realtime-api/token), then connect with the token.
  </Tab>
</Tabs>
