Skip to content

Commit 0b31b6f

Browse files
Working well
1 parent 44efcc1 commit 0b31b6f

File tree

4 files changed

+54
-82
lines changed

4 files changed

+54
-82
lines changed

docs-v2/components/AccountConnectionDemo.jsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { useGlobalConnect } from "./GlobalConnectProvider";
44
import CodeBlock from "./CodeBlock";
55

66
export default function AccountConnectionDemo() {
7-
const {
8-
appSlug,
9-
setAppSlug,
10-
tokenData,
11-
getClientCodeSnippet,
7+
const {
8+
appSlug,
9+
setAppSlug,
10+
tokenData,
11+
getClientCodeSnippet,
1212
connectAccount,
1313
connectedAccount,
14-
error
14+
error,
1515
} = useGlobalConnect();
1616

1717
return (
@@ -34,7 +34,7 @@ export default function AccountConnectionDemo() {
3434
<option value="google_sheets">Google Sheets</option>
3535
</select>
3636
</label>
37-
37+
3838
<div className="mb-4">
3939
<div className="border border-blue-100 rounded-lg overflow-hidden">
4040
<CodeBlock code={getClientCodeSnippet()} language="javascript" />
@@ -50,6 +50,7 @@ export default function AccountConnectionDemo() {
5050
>
5151
Connect Account
5252
</button>
53+
{!tokenData && <p className="mt-2 text-sm text-gray-500"><a href="/docs/connect/managed-auth/quickstart/#generate-a-short-lived-token" className="font-semibold underline underline-offset-4 hover:decoration-2 decoration-brand/50">Generate a token above</a> in order to test the account connection flow</p>}
5354
</div>
5455

5556
{error && (
@@ -58,7 +59,7 @@ export default function AccountConnectionDemo() {
5859
<div className="mt-1 text-sm">{error}</div>
5960
</div>
6061
)}
61-
62+
6263
{connectedAccount && (
6364
<div className="mt-4 p-3 bg-green-50 border border-green-200 text-green-800 rounded-md">
6465
<div className="font-medium text-sm">Account successfully connected!</div>
@@ -75,4 +76,4 @@ export default function AccountConnectionDemo() {
7576
</div>
7677
</div>
7778
);
78-
}
79+
}

docs-v2/components/ConnectCodeSnippets.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,30 @@ const { token, expires_at, connect_link_url } = await pd.createConnectToken({
3636
export function getClientCodeSnippet(appSlug, tokenData) {
3737
return `import { createFrontendClient } from "@pipedream/sdk/browser"
3838
39-
// This code runs in the browser
40-
const pd = createFrontendClient()
41-
42-
// Connect an account using the token from your server
43-
pd.connectAccount({
44-
app: "${appSlug}",
45-
token: "${tokenData?.token
39+
// This code runs in the frontend using the token from your server
40+
export default function Home() {
41+
function connectAccount() {
42+
const pd = createFrontendClient()
43+
pd.connectAccount({
44+
app: "${appSlug}",
45+
token: "${tokenData?.token
4646
? tokenData.token.substring(0, 10) + "..."
47-
: "YOUR_TOKEN"}",
48-
onSuccess: (account) => {
49-
// Handle successful connection
50-
console.log(\`Account successfully connected: \${account.name}\`)
51-
},
52-
onError: (err) => {
53-
// Handle connection error
54-
console.error(\`Connection error: \${err.message}\`)
55-
},
56-
onClose: () => {
57-
// Handle dialog closed by user
47+
: "{connect_token}"}",
48+
onSuccess: (account) => {
49+
// Handle successful connection
50+
console.log(\`Account successfully connected: \${account.id}\`)
51+
},
52+
onError: (err) => {
53+
// Handle connection error
54+
console.error(\`Connection error: \${err.message}\`)
55+
}
56+
})
5857
}
59-
})`;
58+
59+
return (
60+
<main>
61+
<button onClick={connectAccount}>Connect Account</button>
62+
</main>
63+
)
64+
}`;
6065
}

docs-v2/components/TokenGenerationDemo.jsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { useGlobalConnect } from "./GlobalConnectProvider";
44
import CodeBlock from "./CodeBlock";
55

66
export default function TokenGenerationDemo() {
7-
const {
8-
externalUserId,
9-
getServerCodeSnippet,
10-
generateToken,
7+
const {
8+
externalUserId,
9+
getServerCodeSnippet,
10+
generateToken,
1111
tokenLoading,
12-
tokenData
12+
tokenData,
1313
} = useGlobalConnect();
1414

1515
return (
@@ -36,23 +36,25 @@ export default function TokenGenerationDemo() {
3636
disabled={tokenLoading}
3737
className="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 transition-colors disabled:opacity-50 font-medium text-sm"
3838
>
39-
{tokenLoading ? "Generating..." : "Generate Token"}
39+
{tokenLoading
40+
? "Generating..."
41+
: "Generate Token"}
4042
</button>
4143
</div>
4244

4345
{tokenData && (
4446
<div className="mt-4">
45-
<div className="text-sm mb-2 font-medium">Server Response:</div>
47+
<div className="text-sm mb-2 font-medium">Response:</div>
4648
<div className="border border-green-200 rounded-lg overflow-hidden">
47-
<CodeBlock
48-
code={JSON.stringify(tokenData, null, 2)}
49-
language="json"
50-
className="max-h-48 overflow-auto"
49+
<CodeBlock
50+
code={JSON.stringify(tokenData, null, 2)}
51+
language="json"
52+
className="max-h-48 overflow-auto"
5153
/>
5254
</div>
5355
</div>
5456
)}
5557
</div>
5658
</div>
5759
);
58-
}
60+
}

docs-v2/pages/connect/managed-auth/quickstart.mdx

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ Here's how Connect sits in your frontend and backend, and communicates with Pipe
2424
<br />
2525
<Image src="https://res.cloudinary.com/pipedreamin/image/upload/v1723834101/docs/Screenshot_2024-08-16_at_11.48.15_AM_kijxa7.png" alt="Connect developer flow" width={800} height={500} />
2626

27-
## Interactive Demo
28-
29-
Below, we'll walk through the full implementation step by step, with interactive examples you can try.
30-
3127
## Getting started
3228

3329
<Steps>
@@ -121,53 +117,21 @@ Try the interactive demo below to connect an account after generating a token in
121117
<AccountConnectionDemo />
122118
</div>
123119

124-
In our example Next.js app, `app/page.tsx` calls the `connectAccount` method from the Pipedream SDK when the user clicks the **Connect your account** button, similar to how our interactive demo above works.
125-
126-
<br />
127-
<Image src="https://res.cloudinary.com/pipedreamin/image/upload/v1733865948/Google_Chrome_-_Pipedream_Connect_Demo_2024-12-10_at_1.23.47_PM_mwxfzh.png" alt="Connect your account button" width={650} height={300} />
128-
129-
```typescript
130-
import { createFrontendClient } from "@pipedream/sdk/browser"
131-
132-
export default function Home() {
133-
const pd = createFrontendClient()
134-
function connectAccount() {
135-
pd.connectAccount({
136-
app: appSlug, // Pass the app name slug of the app you want to integrate
137-
oauthAppId: appId, // For OAuth apps, pass the OAuth app ID; omit this param to use Pipedream's OAuth client or for key-based apps
138-
token: "YOUR_TOKEN", // The token you received from your server above
139-
onSuccess: ({ id: accountId }) => {
140-
console.log(`Account successfully connected: ${accountId}`)
141-
}
142-
})
143-
}
144-
145-
return (
146-
<main>
147-
<button onClick={connectAccount}>Connect your account</button>
148-
</main>
149-
)
150-
}
151-
```
152-
153-
Press that button to connect an account for the app you configured.
154-
155120
#### Or use Connect Link
156121

157-
Use this option when you can't execute JavaScript or open an iFrame in your environment (e.g. mobile apps), or when you want to offload the account connection flow to Pipedream and avoid frontend work. You can also send these links via email or SMS.
122+
Use this option when you can't execute JavaScript or open an iFrame in your environment (e.g. mobile apps) and instead want to share a URL with your end users.
158123

159-
The Connect Link opens a Pipedream-hosted page, guiding users through the account connection process. The URL is specific to the user and expires after 4 hours.
124+
The Connect Link URL opens a Pipedream-hosted page, guiding users through the account connection process. The URL is specific to the user and expires after 4 hours.
160125

161-
1. First, [generate a token](#generate-a-short-lived-token) for your users.
162-
2. Extract the `connect_link_url` from the token response.
163-
3. Before returning the URL to your user, add an `app` parameter to the end of the query string:
126+
1. First, [generate a token](#generate-a-short-lived-token) for your users
127+
2. Check out the [optional arguments](/connect/api/#create-a-new-token) to define redirect URLs on success or error
128+
3. Extract the `connect_link_url` from the token response
129+
4. Before returning the URL to your user, add an `app` parameter to the end of the query string:
164130

165131
```
166132
https://pipedream.com/_static/connect.html?token={token}&connectLink=true&app={appSlug}&oauthAppId={oauthAppId}
167133
```
168134

169-
4. Redirect your users to this URL, or send it to them via email, SMS, and more.
170-
171135
### Make authenticated requests
172136

173137
Now that your users have connected an account, you can use their auth in one of a few ways:

0 commit comments

Comments
 (0)