You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/realtime/auth.mdx
+41-79Lines changed: 41 additions & 79 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,23 @@
1
1
---
2
2
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
5
5
---
6
6
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.
8
8
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
10
21
11
22
You can create a Public Access Token using the `auth.createPublicToken` function in your **backend** code:
12
23
@@ -16,7 +27,7 @@ import { auth } from "@trigger.dev/sdk/v3";
16
27
const publicToken =awaitauth.createPublicToken(); // 👈 this public access token has no permissions, so is pretty useless!
17
28
```
18
29
19
-
## Scopes
30
+
###Scopes
20
31
21
32
By default a Public Access Token has no permissions. You must specify the scopes you need when creating a Public Access Token:
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.
123
134
124
-
## Auto-generated tokens
135
+
###Auto-generated tokens
125
136
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.
127
138
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.
See our [triggering documentation](/triggering) for detailed examples of how to trigger tasks and get auto-generated tokens.
132
142
133
-
console.log(handle.publicAccessToken);
134
-
```
143
+
### Subscribing to runs with Public Access Tokens
135
144
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.
137
146
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.
140
148
141
-
const handle =awaittasks.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.
154
150
155
-
You will also get back a Public Access Token when using the `batchTrigger` function:
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.
### Triggering tasks from frontend with Trigger Tokens
237
202
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.
242
204
243
205
See our [React hooks documentation](/realtime/react-hooks) for more details on using hooks in your frontend application.
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.
10
10
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
12
21
13
22
You can subscribe to real-time updates for:
14
23
@@ -17,7 +26,7 @@ You can subscribe to real-time updates for:
17
26
-**Task runs** - All runs for specific tasks
18
27
-**Batch runs** - All runs in a batch
19
28
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:
21
30
22
31
- Run status changes (queued → executing → completed, etc.)
23
32
-[Run metadata](/runs/metadata) is updated
@@ -29,23 +38,15 @@ Your tasks can also send additional custom data:
29
38
-**Metadata updates** - Update custom metadata on runs that gets streamed to subscribers ([backend](/realtime/backend/metadata) | [React hooks](/realtime/react-hooks/realtime#using-metadata))
30
39
-**Stream function** - Stream data chunks in real-time, perfect for AI/LLM streaming ([backend](/realtime/backend/streams) | [React hooks](/realtime/react-hooks/streams))
31
40
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
-
40
41
## Implementation approaches
41
42
42
-
### Backend subscriptions
43
+
### Backend implementation
43
44
44
45
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.
Copy file name to clipboardExpand all lines: docs/realtime/react-hooks/triggering.mdx
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,12 @@ import RealtimeExamplesCards from "/snippets/realtime-examples-cards.mdx";
8
8
9
9
We provide a set of hooks that can be used to trigger tasks from your frontend application.
10
10
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)
0 commit comments