@@ -3,6 +3,7 @@ import { getThirdwebBaseUrl } from "../../../../utils/domains.js";
33import { getClientFetch } from "../../../../utils/fetch.js" ;
44import type { OneOf , Prettify } from "../../../../utils/type-utils.js" ;
55import type { Profile } from "../authentication/types.js" ;
6+ import type { Ecosystem } from "../wallet/types.js" ;
67
78export type GetUserResult = {
89 userId : string ;
@@ -17,24 +18,23 @@ export type GetUserResult = {
1718 * Gets user based on the provided query parameters.
1819 * @note This function is only available on the server (a secret key is required in the client).
1920 *
20- * @param options - The options for the find users function.
21+ * @param options - The options for the get user function.
2122 * @param options.client - The Thirdweb client with a secret key included.
22- * @param [options.walletAddress] - The wallet address to query by.
23+ * @param [options.walletAddress] - The wallet address generated by thirdweb to query by.
2324 * @param [options.email] - The email to query by.
2425 * @param [options.phone] - The phone number to query by.
2526 * @param [options.id] - The user ID to query by.
27+ * @param [options.externalWalletAddress] - The external wallet address used to login via SIWE.
2628 *
27- * @returns An array of user objects .
29+ * @returns A user object or null if not found .
2830 *
2931 * @example
30- * ```ts
3132 * import { getUser } from "thirdweb/wallets";
3233 *
3334 * const user = await getUser({
3435 * client,
3536 * walletAddress: "0x123...",
3637 * });
37- * ```
3838 *
3939 * @wallet
4040 */
@@ -44,14 +44,18 @@ export async function getUser({
4444 email,
4545 phone,
4646 id,
47+ externalWalletAddress,
48+ ecosystem,
4749} : Prettify <
4850 {
4951 client : ThirdwebClient ;
52+ ecosystem ?: Ecosystem ;
5053 } & OneOf < {
5154 walletAddress ?: string ;
5255 email ?: string ;
5356 phone ?: string ;
5457 id ?: string ;
58+ externalWalletAddress ?: string ;
5559 } >
5660> ) : Promise < GetUserResult | null > {
5761 if ( ! client . secretKey ) {
@@ -76,15 +80,27 @@ export async function getUser({
7680 } else if ( id ) {
7781 url . searchParams . set ( "queryBy" , "id" ) ;
7882 url . searchParams . set ( "id" , id ) ;
83+ } else if ( externalWalletAddress ) {
84+ url . searchParams . set ( "queryBy" , "externalWalletAddress" ) ;
85+ url . searchParams . set ( "externalWalletAddress" , externalWalletAddress ) ;
7986 } else {
8087 throw new Error (
81- "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." ,
8289 ) ;
8390 }
8491
8592 const clientFetch = getClientFetch ( client ) ;
8693
87- const res = await clientFetch ( url . toString ( ) ) ;
94+ const res = await clientFetch ( url . toString ( ) , {
95+ headers : {
96+ ...( ecosystem ?. id
97+ ? { "x-ecosystem-id" : `ecosystem.${ ecosystem . id } ` }
98+ : { } ) ,
99+ ...( ecosystem ?. partnerId
100+ ? { "x-ecosystem-partner-id" : ecosystem . partnerId }
101+ : { } ) ,
102+ } ,
103+ } ) ;
88104
89105 if ( ! res . ok ) {
90106 throw new Error ( "Failed to get profiles" ) ;
0 commit comments