Skip to content

Commit 0f6b881

Browse files
committed
docs: update fetching user details endpoint for ecosystems (#4918)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the `getUser` functionality in the `thirdweb` SDK by adding support for querying user details via an external wallet address and ecosystem identifiers. ### Detailed summary - Added support for querying user details using `externalWalletAddress` in `getUser`. - Updated documentation for `getUser` to include `externalWalletAddress` as a query parameter. - Modified examples in the documentation to demonstrate querying with `externalWalletAddress`. - Updated user detail query parameters in documentation to reflect new options. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 4dee169 commit 0f6b881

File tree

3 files changed

+87
-14
lines changed

3 files changed

+87
-14
lines changed

.changeset/sixty-cats-doubt.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Add querying for in app wallet user details via externally linked wallet address:
6+
7+
```ts
8+
import { getUser } from "thirdweb";
9+
10+
// this is the wallet address that the user used to connect via SIWE to their in app wallet
11+
const user = await getUser({
12+
client,
13+
externalWalletAddress: "0x123...",
14+
});
15+
```
16+
17+
Add querying for ecosystem wallet user details:
18+
19+
```ts
20+
import { getUser } from "thirdweb";
21+
22+
const user = await getUser({
23+
client,
24+
ecosystem: {
25+
id: "ecosystem.YOUR_ID",
26+
partnerId: "OPTIONAL_PARTNER_ID"
27+
}
28+
email: "user@example.com",
29+
});
30+
```

apps/portal/src/app/connect/in-app-wallet/guides/get-user-details/page.mdx

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ You can query user details through the thirdweb SDK using a wallet address, emai
99
<Tabs defaultValue='wallet'>
1010
<TabsList>
1111
<TabsTrigger value='wallet'>Wallet</TabsTrigger>
12+
<TabsTrigger value='external-wallet'>External Wallet</TabsTrigger>
1213
<TabsTrigger value='email'>Email</TabsTrigger>
1314
<TabsTrigger value='phone'>Phone</TabsTrigger>
1415
<TabsTrigger value='id'>User ID</TabsTrigger>
@@ -18,13 +19,26 @@ You can query user details through the thirdweb SDK using a wallet address, emai
1819
```ts
1920
import { getUser } from "thirdweb";
2021

22+
// this is the wallet address that thirdweb has generated for the user
2123
const user = await getUser({
2224
client,
2325
walletAddress: "0x123...",
2426
});
2527
```
2628
</TabsContent>
2729

30+
<TabsContent value='external-wallet'>
31+
```ts
32+
import { getUser } from "thirdweb";
33+
34+
// this is the wallet address that the user used to connect via SIWE to their in app wallet
35+
const user = await getUser({
36+
client,
37+
externalWalletAddress: "0x123...",
38+
});
39+
```
40+
</TabsContent>
41+
2842
<TabsContent value='email'>
2943
```ts
3044
import { getUser } from "thirdweb";
@@ -70,27 +84,52 @@ https://embedded-wallet.thirdweb.com/api/2023-11-30/embedded-wallet/user-details
7084

7185
### Query Parameters
7286

73-
You can query user details using one of the following parameters:
87+
You can specify the query parameter `queryBy` to query by different user identifiers:
88+
89+
- `queryBy`: The parameter to query by. Can be one of `walletAddress`, `email`, `phone`, `externalWalletAddress`, or `id`.
90+
91+
You can then specify the value to query by, matching the queryBy parameter:
7492

75-
- `walletAddress`: The user's wallet address
93+
- `walletAddress`: The user's wallet address that thirdweb has generated for them
7694
- `email`: The user's email address
7795
- `phone`: The user's phone number
78-
- `id`: The user's ID
96+
- `externalWalletAddress`: The user's wallet address that used to login via SIWE
97+
- `id`: The user's ID (for custom auth)
7998

8099
### Authentication
81100

82-
You need to include your ThirdWeb Client Secret in the Authorization header.
101+
You need to include your ThirdWeb Client Secret in the Authorization header.
102+
103+
If you are an ecosystem owner, you have to include the `x-ecosystem-id` header and optionally the `x-ecosystem-partner-id` header if the ecosystem is set to partners only.
83104

84105
### Example curl Command
85106

86-
Here's an example curl command to fetch user details:
107+
Here's an example curl command to fetch user details by email:
108+
109+
```bash
110+
curl -X GET 'https://embedded-wallet.thirdweb.com/api/2023-11-30/embedded-wallet/user-details?queryBy=email&email=user@example.com' \
111+
-H 'x-secret-key: YOUR_THIRD_WEB_CLIENT_SECRET'
112+
```
113+
114+
Here's an example curl command to fetch user details by address:
87115

88116
```bash
89117
curl -X GET 'https://embedded-wallet.thirdweb.com/api/2023-11-30/embedded-wallet/user-details?queryBy=walletAddress&walletAddress=0x123456789abcdef' \
90-
-H 'Authorization: Bearer YOUR_THIRD_WEB_CLIENT_SECRET'
118+
-H 'x-secret-key: YOUR_THIRD_WEB_CLIENT_SECRET'
91119
```
92120

93-
Replace `YOUR_THIRD_WEB_CLIENT_SECRET` with your actual ThirdWeb Client Secret.
121+
Here's an example curl command to fetch the user details for an ecosystem owner:
122+
123+
```bash
124+
curl -X GET 'https://embedded-wallet.thirdweb.com/api/2023-11-30/embedded-wallet/user-details?queryBy=walletAddress&walletAddress=0x123456789abcdef' \
125+
-H 'x-secret-key: YOUR_THIRD_WEB_CLIENT_SECRET' \
126+
-H 'x-ecosystem-id: ecosystem.YOUR_ECOSYSTEM_ID' \
127+
-H 'x-ecosystem-partner-id: YOUR_PARTNER_ID'
128+
```
129+
130+
In both examples, replace `YOUR_THIRD_WEB_CLIENT_SECRET` with your actual ThirdWeb Client Secret.
131+
132+
Replace `YOUR_ECOSYSTEM_ID` and `YOUR_PARTNER_ID` with your actual ecosystem ID and partner ID respectively. The partner ID can be one you set up for yourself as the ecosystem owner.
94133

95134
### Response Format
96135

packages/thirdweb/src/wallets/in-app/core/users/getUser.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,23 @@ export type GetUserResult = {
1818
* Gets user based on the provided query parameters.
1919
* @note This function is only available on the server (a secret key is required in the client).
2020
*
21-
* @param options - The options for the find users function.
21+
* @param options - The options for the get user function.
2222
* @param options.client - The Thirdweb client with a secret key included.
23-
* @param [options.walletAddress] - The wallet address to query by.
23+
* @param [options.walletAddress] - The wallet address generated by thirdweb to query by.
2424
* @param [options.email] - The email to query by.
2525
* @param [options.phone] - The phone number to query by.
2626
* @param [options.id] - The user ID to query by.
27+
* @param [options.externalWalletAddress] - The linked external wallet address to query by.
2728
*
28-
* @returns An array of user objects.
29+
* @returns A user object or null if not found.
2930
*
3031
* @example
31-
* ```ts
3232
* import { getUser } from "thirdweb/wallets";
3333
*
3434
* const user = await getUser({
3535
* client,
3636
* walletAddress: "0x123...",
3737
* });
38-
* ```
3938
*
4039
* @wallet
4140
*/
@@ -45,16 +44,18 @@ export async function getUser({
4544
email,
4645
phone,
4746
id,
47+
externalWalletAddress,
4848
ecosystem,
4949
}: Prettify<
5050
{
5151
client: ThirdwebClient;
52+
ecosystem?: Ecosystem;
5253
} & OneOf<{
5354
walletAddress?: string;
5455
email?: string;
5556
phone?: string;
5657
id?: string;
57-
ecosystem?: Ecosystem;
58+
externalWalletAddress?: string;
5859
}>
5960
>): Promise<GetUserResult | null> {
6061
if (!client.secretKey) {
@@ -79,9 +80,12 @@ export async function getUser({
7980
} else if (id) {
8081
url.searchParams.set("queryBy", "id");
8182
url.searchParams.set("id", id);
83+
} else if (externalWalletAddress) {
84+
url.searchParams.set("queryBy", "externalWalletAddress");
85+
url.searchParams.set("externalWalletAddress", externalWalletAddress);
8286
} else {
8387
throw new Error(
84-
"Please provide a walletAddress, email, phone, or id to query for users.",
88+
"Please provide a walletAddress, email, phone, id, or externalWalletAddress to query for users.",
8589
);
8690
}
8791

0 commit comments

Comments
 (0)