Skip to content

Commit fd37ce7

Browse files
committed
Updated the structure
1 parent 1a8cf5b commit fd37ce7

File tree

5 files changed

+64
-98
lines changed

5 files changed

+64
-98
lines changed

docs/docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"pages": [
124124
"realtime/react-hooks/overview",
125125
"realtime/react-hooks/triggering",
126-
"realtime/react-hooks/realtime",
126+
"realtime/react-hooks/subscribe",
127127
"realtime/react-hooks/streams",
128128
"realtime/react-hooks/swr"
129129
]

docs/realtime/auth.mdx

Lines changed: 41 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
---
22
title: Realtime authentication
3-
sidebarTitle: Realtime authentication
4-
description: Authenticating real-time API requests with Public Access Tokens
3+
sidebarTitle: Realtime auth
4+
description: Authenticating real-time API requests with Public Access Tokens or Trigger Tokens
55
---
66

7-
To use the Realtime API, you need to authenticate your requests with Public Access Tokens. These tokens provide secure, scoped access to your runs and can be used in both frontend and backend applications.
7+
To use the Realtime API, you need to authenticate your requests with Public Access Tokens or Trigger Tokens. These tokens provide secure, scoped access to your runs and can be used in both frontend and backend applications.
88

9-
## Creating Public Access Tokens
9+
## Token Types
10+
11+
There are two types of tokens you can use with the Realtime API:
12+
13+
- **[Public Access Tokens](#public-access-tokens-for-subscribing-to-runs)** - Used to read and subscribe to run data. Can be used in both frontend and backend applications.
14+
- **[Trigger Tokens](#trigger-tokens-for-frontend-triggering-only)** - Used to trigger tasks from your frontend. These are more secure, single-use tokens that can only be used in frontend applications.
15+
16+
## Public Access Tokens (for subscribing to runs)
17+
18+
Public Access Tokens are used to read and subscribe to run data. They can be used in both frontend and backend applications to subscribe to runs.
19+
20+
### Creating Public Access Tokens
1021

1122
You can create a Public Access Token using the `auth.createPublicToken` function in your **backend** code:
1223

@@ -16,7 +27,7 @@ import { auth } from "@trigger.dev/sdk/v3";
1627
const publicToken = await auth.createPublicToken(); // 👈 this public access token has no permissions, so is pretty useless!
1728
```
1829

19-
## Scopes
30+
### Scopes
2031

2132
By default a Public Access Token has no permissions. You must specify the scopes you need when creating a Public Access Token:
2233

@@ -103,7 +114,7 @@ const publicToken = await auth.createPublicToken({
103114
});
104115
```
105116

106-
## Expiration
117+
### Expiration
107118

108119
By default, Public Access Token's expire after 15 minutes. You can specify a different expiration time when creating a Public Access Token:
109120

@@ -121,72 +132,36 @@ const publicToken = await auth.createPublicToken({
121132

122133
The format used for a time span is the same as the [jose package](https://github.com/panva/jose), which is a number followed by a unit. Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an alias for a year. If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability when adding to the current unix timestamp.
123134

124-
## Auto-generated tokens
135+
### Auto-generated tokens
125136

126-
When triggering a task from your backend, the `handle` received from the `trigger` function now includes a `publicAccessToken` field. This token can be used to authenticate requests in your frontend application:
137+
When you [trigger tasks](/triggering) from your backend, the `handle` received includes a `publicAccessToken` field. This token can be used to authenticate real-time requests in your frontend application.
127138

128-
```ts
129-
import { tasks } from "@trigger.dev/sdk/v3";
139+
By default, auto-generated tokens expire after 15 minutes and have a read scope for the specific run(s) that were triggered. You can customize the expiration by passing a `publicTokenOptions` object to the trigger function.
130140

131-
const handle = await tasks.trigger("my-task", { some: "data" });
141+
See our [triggering documentation](/triggering) for detailed examples of how to trigger tasks and get auto-generated tokens.
132142

133-
console.log(handle.publicAccessToken);
134-
```
143+
### Subscribing to runs with Public Access Tokens
135144

136-
By default, tokens returned from the `trigger` function expire after 15 minutes and have a read scope for that specific run. You can customize the expiration of the auto-generated tokens by passing a `publicTokenOptions` object to the `trigger` function:
145+
Once you have a Public Access Token, you can use it to authenticate requests to the Realtime API in both backend and frontend applications.
137146

138-
```ts
139-
import { tasks } from "@trigger.dev/sdk/v3";
147+
**Backend usage:** See our [backend subscription documentation](/realtime/backend/subscribe) for examples of using tokens with backend functions.
140148

141-
const handle = await tasks.trigger(
142-
"my-task",
143-
{ some: "data" },
144-
{
145-
tags: ["my-tag"],
146-
},
147-
{
148-
publicAccessToken: {
149-
expirationTime: "1hr",
150-
},
151-
}
152-
);
153-
```
149+
**Frontend usage:** See our [React hooks documentation](/realtime/react-hooks) for examples of using tokens with frontend components.
154150

155-
You will also get back a Public Access Token when using the `batchTrigger` function:
156-
157-
```ts
158-
import { tasks } from "@trigger.dev/sdk/v3";
159-
160-
const handle = await tasks.batchTrigger("my-task", [
161-
{ payload: { some: "data" } },
162-
{ payload: { some: "data" } },
163-
{ payload: { some: "data" } },
164-
]);
165-
166-
console.log(handle.publicAccessToken);
167-
```
168-
169-
## Trigger tokens
151+
## Trigger Tokens (for frontend triggering only)
170152

171153
For triggering tasks from your frontend, you need special "trigger" tokens. These tokens can only be used once to trigger a task and are more secure than regular Public Access Tokens.
172154

155+
### Creating Trigger Tokens
156+
173157
```ts
174158
import { auth } from "@trigger.dev/sdk/v3";
175159

176160
// Somewhere in your backend code
177161
const triggerToken = await auth.createTriggerPublicToken("my-task");
178162
```
179163

180-
These tokens also expire, with the default expiration time being 15 minutes. You can specify a custom expiration time:
181-
182-
```ts
183-
import { auth } from "@trigger.dev/sdk/v3";
184-
185-
// Somewhere in your backend code
186-
const triggerToken = await auth.createTriggerPublicToken("my-task", {
187-
expirationTime: "24hr",
188-
});
189-
```
164+
### Multiple tasks
190165

191166
You can pass multiple tasks to create a token that can trigger multiple tasks:
192167

@@ -197,6 +172,8 @@ import { auth } from "@trigger.dev/sdk/v3";
197172
const triggerToken = await auth.createTriggerPublicToken(["my-task-1", "my-task-2"]);
198173
```
199174

175+
### Multiple use
176+
200177
You can also create tokens that can be used multiple times:
201178

202179
```ts
@@ -208,36 +185,21 @@ const triggerToken = await auth.createTriggerPublicToken("my-task", {
208185
});
209186
```
210187

211-
## Using tokens
188+
### Expiration
212189

213-
Once you have a Public Access Token, you can use it to authenticate requests to the Realtime API:
214-
215-
### Backend usage
190+
These tokens also expire, with the default expiration time being 15 minutes. You can specify a custom expiration time:
216191

217192
```ts
218-
import { runs } from "@trigger.dev/sdk/v3";
219-
220-
// Using the token with backend functions
221-
for await (const run of runs.subscribeToRun("run_1234", {
222-
accessToken: publicToken,
223-
})) {
224-
console.log(run);
225-
}
226-
```
227-
228-
### Frontend usage
193+
import { auth } from "@trigger.dev/sdk/v3";
229194

230-
```tsx
231-
import { useRealtimeRun } from "@trigger.dev/react-hooks";
195+
// Somewhere in your backend code
196+
const triggerToken = await auth.createTriggerPublicToken("my-task", {
197+
expirationTime: "24hr",
198+
});
199+
```
232200

233-
export function MyComponent({ runId, publicAccessToken }) {
234-
const { run, error } = useRealtimeRun(runId, {
235-
accessToken: publicAccessToken,
236-
});
201+
### Triggering tasks from frontend with Trigger Tokens
237202

238-
if (error) return <div>Error: {error.message}</div>;
239-
return <div>Run: {run?.id}</div>;
240-
}
241-
```
203+
To trigger tasks from your frontend, you need to use special Trigger Tokens created in your backend. See our [React hooks triggering documentation](/realtime/react-hooks/triggering) for complete examples.
242204

243205
See our [React hooks documentation](/realtime/react-hooks) for more details on using hooks in your frontend application.

docs/realtime/overview.mdx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ description: Using the Trigger.dev Realtime API to subscribe to runs in real-tim
66

77
import RealtimeExamplesCards from "/snippets/realtime-examples-cards.mdx";
88

9-
Trigger.dev Realtime allows you subscribe to runs and get real-time updates as they execute. This is useful for monitoring runs, updating UIs, and building real-time dashboards.
9+
Trigger.dev Realtime allows you to trigger, subscribe to, and get real-time updates for runs. This is useful for monitoring runs, updating UIs, and building real-time dashboards.
1010

11-
## What you can subscribe to
11+
## Authentication
12+
13+
All Realtime subscriptions require authentication so you can securely trigger and subscribe to runs. See our [authentication guide](/realtime/auth) for details on:
14+
15+
- Creating Public Access Tokens to subscribe to runs
16+
- Creating Trigger Tokens to trigger tasks from your frontend
17+
- Scoping tokens to specific runs, tasks, tags, or batches
18+
- Auto-generated tokens from `tasks.trigger()`
19+
20+
## How run subscriptions work
1221

1322
You can subscribe to real-time updates for:
1423

@@ -17,7 +26,7 @@ You can subscribe to real-time updates for:
1726
- **Task runs** - All runs for specific tasks
1827
- **Batch runs** - All runs in a batch
1928

20-
You automatically receive the complete [run object](/realtime/run-object) containing status, timestamps, metadata, tags, and more whenever:
29+
When you subscribe to runs, you automatically receive the complete [run object](/realtime/run-object) containing status, timestamps, metadata, tags, and more whenever:
2130

2231
- Run status changes (queued → executing → completed, etc.)
2332
- [Run metadata](/runs/metadata) is updated
@@ -29,23 +38,15 @@ Your tasks can also send additional custom data:
2938
- **Metadata updates** - Update custom metadata on runs that gets streamed to subscribers ([backend](/realtime/backend/metadata) | [React hooks](/realtime/react-hooks/realtime#using-metadata))
3039
- **Stream function** - Stream data chunks in real-time, perfect for AI/LLM streaming ([backend](/realtime/backend/streams) | [React hooks](/realtime/react-hooks/streams))
3140

32-
## Authentication
33-
34-
All Realtime subscriptions require authentication. See our [authentication guide](/realtime/auth) for details on:
35-
36-
- Creating Public Access Tokens for frontend use
37-
- Scoping tokens to specific runs, tasks, tags, or batches
38-
- Auto-generated tokens from `tasks.trigger()`
39-
4041
## Implementation approaches
4142

42-
### Backend subscriptions
43+
### Backend implementation
4344

4445
Use our server-side SDK to subscribe to runs from your backend code, other tasks, or serverless functions. Perfect for triggering workflows, sending notifications, or updating databases based on run status changes.
4546

4647
**[See Backend functions guide](/realtime/backend)**
4748

48-
### Frontend subscriptions
49+
### Frontend implementation
4950

5051
Use our React hooks to build real-time UIs that update as runs execute. Ideal for progress bars, status indicators, and live dashboards.
5152

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Realtime hooks
3-
sidebarTitle: Realtime
2+
title: Subscribing to runs
3+
sidebarTitle: Subscribe
44
description: Get live updates from runs, batches, metadata, and more in your frontend application.
55
---
66

docs/realtime/react-hooks/triggering.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import RealtimeExamplesCards from "/snippets/realtime-examples-cards.mdx";
88

99
We provide a set of hooks that can be used to trigger tasks from your frontend application.
1010

11-
## Demo
12-
13-
We've created a [Demo application](https://github.com/triggerdotdev/realtime-llm-battle) that demonstrates how to use our React hooks to trigger tasks in a Next.js application. The application uses the `@trigger.dev/react-hooks` package to trigger a task and subscribe to the run in real-time.
11+
<Note>
12+
For triggering tasks from your frontend, you need to use “trigger” tokens. These can only be used
13+
once to trigger a task and are more secure than regular Public Access Tokens. To learn more about
14+
how to create and use these tokens, see our [Trigger Tokens](/realtime/auth#trigger-tokens)
15+
documentation.
16+
</Note>
1417

1518
## Hooks
1619

0 commit comments

Comments
 (0)