@@ -131,13 +131,6 @@ const client = new PipedreamClient({
131131 projectId: ' your-project-id' ,
132132 projectEnvironment: ' development' , // or 'production'
133133});
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- });
141134```
142135
143136### Browser-side
@@ -162,39 +155,41 @@ const frontendClient = createFrontendClient({
162155
163156The v2.x SDK provides two options for browser-side usage:
164157
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 )**
167160
168161``` javascript
169162import { PipedreamClient } from ' @pipedream/sdk' ;
170163
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,
173175 projectId: ' your-project-id' ,
174176 projectEnvironment: ' development' , // or 'production'
175177});
176178```
177179
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 )**
180182
181183``` javascript
182184// Explicit browser import (recommended for browser apps)
183- import { createFrontendClient , PipedreamClient } from ' @pipedream/sdk/browser' ;
185+ import { createFrontendClient , type PipedreamClient } from ' @pipedream/sdk/browser' ;
184186
185187// 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' ,
198193 externalUserId: ' user-123'
199194});
200195
0 commit comments