Skip to content

Commit cc792fd

Browse files
committed
docs: clarify browser completion pattern and CORS for wait tokens
1 parent def21b2 commit cc792fd

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

docs/wait-for-token.mdx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Waitpoint tokens pause task runs until you complete the token. They're commonly
88
You can complete a token using the SDK or by making a POST request to the token's URL.
99

1010
<Note>
11-
If you're waiting for data from an [input stream](/tasks/streams#input-streams), use [`inputStream.wait()`](/tasks/streams#wait--suspend-until-data-arrives) instead — it uses waitpoint tokens internally but provides a simpler API with full type safety from your stream definition.
11+
If you're waiting for data from an [input stream](/tasks/streams#input-streams), use
12+
[`inputStream.wait()`](/tasks/streams#wait--suspend-until-data-arrives) instead — it uses
13+
waitpoint tokens internally but provides a simpler API with full type safety from your stream
14+
definition.
1215
</Note>
1316

1417
## Usage
@@ -54,6 +57,38 @@ await wait.completeToken<ApprovalToken>(tokenId, {
5457
});
5558
```
5659

60+
## Completing from the browser
61+
62+
The `publicAccessToken` returned by `wait.createToken()` is scoped to that specific waitpoint and intended for client-side completion. The completion endpoint has CORS enabled, so you can call it directly from client-side code without proxying through your backend.
63+
64+
<Steps>
65+
<Step title="Create the token in your backend">
66+
```ts
67+
const token = await wait.createToken({ timeout: "10m" });
68+
// Pass token.id and token.publicAccessToken to your frontend
69+
```
70+
</Step>
71+
<Step title="Complete the token from the browser">
72+
```ts
73+
await fetch(`https://api.trigger.dev/api/v1/waitpoints/tokens/${tokenId}/complete`, {
74+
method: "POST",
75+
headers: {
76+
"Authorization": `Bearer ${publicAccessToken}`,
77+
"Content-Type": "application/json",
78+
},
79+
body: JSON.stringify({ data: { status: "approved" } }),
80+
});
81+
```
82+
</Step>
83+
</Steps>
84+
85+
<Warning>
86+
The `token.url` (webhook callback URL) is designed for server-to-server use and does **not** have
87+
CORS headers. Don't call it from the browser — use the pattern above instead.
88+
</Warning>
89+
90+
## Completing via webhook callback
91+
5792
Or you can make an HTTP POST request to the `url` it returns. This is an HTTP callback:
5893

5994
```ts

0 commit comments

Comments
 (0)