@@ -131,13 +131,6 @@ const client = new PipedreamClient({
131
131
projectId: ' your-project-id' ,
132
132
projectEnvironment: ' development' , // or 'production'
133
133
});
134
-
135
- // Alternative: Use with a connect token (for simpler authentication)
136
- const clientWithToken = new PipedreamClient ({
137
- token: ' connect-token' ,
138
- projectId: ' your-project-id' ,
139
- projectEnvironment: ' development' , // or 'production'
140
- });
141
134
```
142
135
143
136
### Browser-side
@@ -162,39 +155,41 @@ const frontendClient = createFrontendClient({
162
155
163
156
The v2.x SDK provides two options for browser-side usage:
164
157
165
- ** Option 1: Using PipedreamClient with connect token (for simple token-based
166
- auth )**
158
+ ** Option 1: Using ` PipedreamClient ` with token callback (for dynamic token
159
+ management )**
167
160
168
161
``` javascript
169
162
import { PipedreamClient } from ' @pipedream/sdk' ;
170
163
171
- const frontendClient = new PipedreamClient ({
172
- token: ' connect-token-from-backend' ,
164
+ const tokenCallback = async ({ externalUserId }) => {
165
+ // Call your backend to get a connect token
166
+ const response = await fetch (' /api/pipedream/token' , {
167
+ method: ' POST' ,
168
+ headers: { ' Content-Type' : ' application/json' },
169
+ body: JSON .stringify ({ externalUserId })
170
+ });
171
+ return response .json ();
172
+ };
173
+ const clientWithToken = new PipedreamClient ({
174
+ tokenCallback,
173
175
projectId: ' your-project-id' ,
174
176
projectEnvironment: ' development' , // or 'production'
175
177
});
176
178
```
177
179
178
- ** Option 2: Using createFrontendClient with token callback (for dynamic token
179
- management )**
180
+ ** Option 2: Using ` createFrontendClient ` with connect token (for simple token-based
181
+ auth )**
180
182
181
183
``` javascript
182
184
// Explicit browser import (recommended for browser apps)
183
- import { createFrontendClient , PipedreamClient } from ' @pipedream/sdk/browser' ;
185
+ import { createFrontendClient , type PipedreamClient } from ' @pipedream/sdk/browser' ;
184
186
185
187
// Or automatic browser resolution
186
- import { createFrontendClient , PipedreamClient } from ' @pipedream/sdk' ;
187
-
188
- const client = createFrontendClient ({
189
- tokenCallback: async ({ externalUserId }) => {
190
- // Call your backend to get a connect token
191
- const response = await fetch (' /api/pipedream/token' , {
192
- method: ' POST' ,
193
- headers: { ' Content-Type' : ' application/json' },
194
- body: JSON .stringify ({ externalUserId })
195
- });
196
- return response .json ();
197
- },
188
+ import { createFrontendClient , type PipedreamClient } from ' @pipedream/sdk' ;
189
+
190
+ // `tokenCallback` is also supported here
191
+ const client: PipedreamClient = createFrontendClient ({
192
+ token: ' connect-token' ,
198
193
externalUserId: ' user-123'
199
194
});
200
195
0 commit comments