@@ -11,18 +11,18 @@ You can use our [React hooks](/frontend/react-hooks) in your frontend applicatio
1111To create a Public Access Token, you can use the ` auth.createPublicToken ` function in your ** backend** code:
1212
1313``` tsx
14- const publicToken = await auth .createPublicToken ();
14+ const publicToken = await auth .createPublicToken (); // 👈 this public access token has no permissions, so is pretty useless!
1515```
1616
1717### Scopes
1818
19- By default a Public Access Token has limited permissions. You can specify the scopes you need when creating a Public Access Token:
19+ By default a Public Access Token has no permissions. You must specify the scopes you need when creating a Public Access Token:
2020
2121``` ts
2222const publicToken = await auth .createPublicToken ({
2323 scopes: {
2424 read: {
25- runs: true ,
25+ runs: true , // ❌ this token can read all runs, possibly useful for debugging/testing
2626 },
2727 },
2828});
@@ -34,7 +34,7 @@ This will allow the token to read all runs, which is probably not what you want.
3434const publicToken = await auth .createPublicToken ({
3535 scopes: {
3636 read: {
37- runs: [" run_1234" , " run_5678" ],
37+ runs: [" run_1234" , " run_5678" ], // ✅ this token can read only these runs
3838 },
3939 },
4040});
@@ -46,7 +46,7 @@ You can scope the token to only read certain tasks:
4646const publicToken = await auth .createPublicToken ({
4747 scopes: {
4848 read: {
49- tasks: [" my-task-1" , " my-task-2" ],
49+ tasks: [" my-task-1" , " my-task-2" ], // 👈 this token can read all runs of these tasks
5050 },
5151 },
5252});
@@ -58,7 +58,7 @@ Or tags:
5858const publicToken = await auth .createPublicToken ({
5959 scopes: {
6060 read: {
61- tags: [" my-tag-1" , " my-tag-2" ],
61+ tags: [" my-tag-1" , " my-tag-2" ], // 👈 this token can read all runs with these tags
6262 },
6363 },
6464});
@@ -70,13 +70,13 @@ Or a specific batch of runs:
7070const publicToken = await auth .createPublicToken ({
7171 scopes: {
7272 read: {
73- batch: " batch_1234" ,
73+ batch: " batch_1234" , // 👈 this token can read all runs in this batch
7474 },
7575 },
7676});
7777```
7878
79- You can also combine scopes. For example, to read only certain tasks and tags :
79+ You can also combine scopes. For example, to read runs with specific tags and for specific tasks :
8080
8181``` ts
8282const publicToken = await auth .createPublicToken ({
@@ -105,6 +105,19 @@ const publicToken = await auth.createPublicToken({
105105
106106This will allow the token to trigger the specified tasks. ` tasks ` is the only write scope available at the moment.
107107
108+ We ** strongly** recommend creating short-lived tokens for write scopes, as they can be used to trigger tasks from your frontend application:
109+
110+ ``` ts
111+ const publicToken = await auth .createPublicToken ({
112+ scopes: {
113+ write: {
114+ tasks: [" my-task-1" ], // ✅ this token can trigger this task
115+ },
116+ },
117+ expirationTime: " 1m" , // ✅ this token will expire after 1 minute
118+ });
119+ ```
120+
108121### Expiration
109122
110123By default, Public Access Token's expire after 15 minutes. You can specify a different expiration time when creating a Public Access Token:
@@ -133,7 +146,7 @@ const handle = await tasks.trigger("my-task", { some: "data" });
133146console .log (handle .publicAccessToken );
134147```
135148
136- By default, tokens returned from the ` trigger ` function expire after 15 minutes and have a read scope for that specific run, and any tags associated with it . You can customize the expiration of the auto-generated tokens by passing a ` publicTokenOptions ` object to the ` trigger ` function:
149+ 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:
137150
138151``` ts
139152const handle = await tasks .trigger (
0 commit comments