Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-heads-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/api": patch
---

added support for userId across wallet apis
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import {
} from "@/components/ui/select";
import type { SearchType } from "./types";

const searchTypeLabels: Record<SearchType, string> = {
email: "Email",
phone: "Phone",
id: "Auth Identifier",
address: "Address",
externalWallet: "External Wallet",
userId: "User Identifier",
};

export function AdvancedSearchInput(props: {
onSearch: (searchType: SearchType, query: string) => void;
onClear: () => void;
Expand Down Expand Up @@ -52,7 +61,8 @@ export function AdvancedSearchInput(props: {
<SelectContent>
<SelectItem value="email">Email</SelectItem>
<SelectItem value="phone">Phone</SelectItem>
<SelectItem value="id">ID</SelectItem>
<SelectItem value="id">Auth Identifier</SelectItem>
<SelectItem value="userId">User Identifier</SelectItem>
<SelectItem value="address">Address</SelectItem>
<SelectItem value="externalWallet">External Wallet</SelectItem>
</SelectContent>
Expand All @@ -62,7 +72,7 @@ export function AdvancedSearchInput(props: {
<div className="relative flex-1">
<Input
className="bg-background pl-9 border-r-0 rounded-r-none rounded-l-full"
placeholder={`Search by ${searchType}...`}
placeholder={`Search by ${searchTypeLabels[searchType]}...`}
value={query}
onChange={(e) => setQuery(e.target.value)}
onKeyDown={handleKeyDown}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { CopyTextButton } from "../ui/CopyTextButton";

const getUserIdentifier = (user: WalletUser) => {
const getAuthIdentifier = (user: WalletUser) => {
const mainDetail = user.linkedAccounts[0]?.details;
return (
mainDetail?.id ??
mainDetail?.email ??
mainDetail?.phone ??
mainDetail?.address ??
mainDetail?.id ??
user.id
mainDetail?.address
);
};

const truncateIdentifier = (value: string) => {
if (value.length <= 18) {
return value;
}
return `${value.slice(0, 8)}...${value.slice(-4)}`;
};

export function SearchResults(props: {
results: WalletUser[];
client: ThirdwebClient;
Expand Down Expand Up @@ -51,6 +58,8 @@ export function SearchResults(props: {
const mainDetail = user.linkedAccounts?.[0]?.details;
const email = mainDetail?.email as string | undefined;
const phone = mainDetail?.phone as string | undefined;
const authIdentifier = getAuthIdentifier(user);
const userIdentifier = user.id;

// Get external wallet addresses from linkedAccounts where type is 'siwe'
const externalWalletAccounts =
Expand All @@ -68,7 +77,34 @@ export function SearchResults(props: {
<p className="text-sm font-medium text-muted-foreground">
User Identifier
</p>
<p className="text-sm">{getUserIdentifier(user)}</p>
{userIdentifier ? (
<CopyTextButton
textToShow={truncateIdentifier(userIdentifier)}
textToCopy={userIdentifier}
tooltip="Copy User Identifier"
copyIconPosition="left"
variant="ghost"
/>
) : (
<p className="text-sm">N/A</p>
)}
</div>

<div>
<p className="text-sm font-medium text-muted-foreground">
Auth Identifier
</p>
{authIdentifier ? (
<CopyTextButton
textToShow={truncateIdentifier(authIdentifier)}
textToCopy={authIdentifier}
tooltip="Copy Auth Identifier"
copyIconPosition="left"
variant="ghost"
/>
) : (
<p className="text-sm">N/A</p>
)}
</div>

{walletAddress && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,42 @@ import { SearchResults } from "./SearchResults";
import { searchUsers } from "./searchUsers";
import type { SearchType } from "./types";

const getUserIdentifier = (accounts: WalletUser["linkedAccounts"]) => {
const getAuthIdentifier = (accounts: WalletUser["linkedAccounts"]) => {
const mainDetail = accounts[0]?.details;
return (
mainDetail?.id ??
mainDetail?.email ??
mainDetail?.phone ??
mainDetail?.address ??
mainDetail?.id
mainDetail?.address
);
};

const getExternalWallets = (accounts: WalletUser["linkedAccounts"]) => {
return accounts?.filter((account) => account.type === "siwe") || [];
const getPrimaryEmail = (accounts: WalletUser["linkedAccounts"]) => {
const emailFromPrimary = accounts[0]?.details?.email;
if (emailFromPrimary) {
return emailFromPrimary;
}

const emailAccount = accounts.find((account) => {
return typeof account.details?.email === "string" && account.details.email;
});

if (emailAccount && typeof emailAccount.details.email === "string") {
return emailAccount.details.email;
}

return undefined;
};

const columnHelper = createColumnHelper<WalletUser>();

const truncateIdentifier = (value: string) => {
if (value.length <= 18) {
return value;
}
return `${value.slice(0, 8)}...${value.slice(-4)}`;
};

export function InAppWalletUsersPageContent(
props: {
authToken: string;
Expand All @@ -56,31 +76,48 @@ export function InAppWalletUsersPageContent(
) {
const columns = useMemo(() => {
return [
columnHelper.accessor("id", {
cell: (cell) => {
const userId = cell.getValue();

if (!userId) {
return "N/A";
}

return (
<CopyTextButton
textToShow={truncateIdentifier(userId)}
textToCopy={userId}
tooltip="Copy User Identifier"
copyIconPosition="left"
variant="ghost"
/>
);
},
header: "User Identifier",
id: "user_identifier",
}),
columnHelper.accessor("linkedAccounts", {
cell: (cell) => {
const identifier = getUserIdentifier(cell.getValue());
const identifier = getAuthIdentifier(cell.getValue());

if (!identifier) {
return "N/A";
}

return (
<CopyTextButton
textToShow={
identifier.length > 30
? `${identifier.slice(0, 30)}...`
: identifier
}
textToShow={truncateIdentifier(identifier)}
textToCopy={identifier}
tooltip="Copy User Identifier"
tooltip="Copy Auth Identifier"
copyIconPosition="left"
variant="ghost"
/>
);
},
enableColumnFilter: true,
header: "User Identifier",
id: "user_identifier",
header: "Auth Identifier",
id: "auth_identifier",
}),
columnHelper.accessor("wallets", {
cell: (cell) => {
Expand All @@ -94,33 +131,24 @@ export function InAppWalletUsersPageContent(
}),
columnHelper.accessor("linkedAccounts", {
cell: (cell) => {
const externalWallets = getExternalWallets(cell.getValue());
if (externalWallets.length === 0) {
return <span className="text-muted-foreground text-sm">None</span>;
const email = getPrimaryEmail(cell.getValue());

if (!email) {
return <span className="text-muted-foreground text-sm">N/A</span>;
}

return (
<div className="space-y-1">
{externalWallets.slice(0, 2).map((account) => {
const address = account.details?.address as string | undefined;
return address ? (
<div
key={`external-${address}-${account.details?.id}`}
className="text-xs"
>
<WalletAddress address={address} client={props.client} />
</div>
) : null;
})}
{externalWallets.length > 2 && (
<span className="text-muted-foreground text-xs">
+{externalWallets.length - 2} more
</span>
)}
</div>
<CopyTextButton
textToShow={email}
textToCopy={email}
tooltip="Copy Email"
copyIconPosition="left"
variant="ghost"
/>
);
},
header: "External Wallets",
id: "external_wallets",
header: "Email",
id: "email",
}),
columnHelper.accessor("wallets", {
cell: (cell) => {
Expand Down Expand Up @@ -230,20 +258,17 @@ export function InAppWalletUsersPageContent(
});
const csv = Papa.unparse(
usersWallets.map((row) => {
const externalWallets = getExternalWallets(row.linkedAccounts);
const externalWalletAddresses = externalWallets
.map((account) => account.details?.address)
.filter(Boolean)
.join(", ");
const email = getPrimaryEmail(row.linkedAccounts);

return {
address: row.wallets[0]?.address || "Uninitialized",
created: row.wallets[0]?.createdAt
? new Date(row.wallets[0].createdAt).toISOString()
: "Wallet not created yet",
external_wallets: externalWalletAddresses || "None",
email: email || "N/A",
login_methods: row.linkedAccounts.map((acc) => acc.type).join(", "),
user_identifier: getUserIdentifier(row.linkedAccounts),
auth_identifier: getAuthIdentifier(row.linkedAccounts) || "N/A",
user_identifier: row.id || "N/A",
};
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ configure({
type APIWallet = ListUserWalletsResponses[200]["result"]["wallets"][0];
type APIProfile = APIWallet["profiles"][0];

// Transform API response to match existing WalletUser format
// Transform API response to match wallet user format
function transformToWalletUser(apiWallet: APIWallet): WalletUser {
return {
id: getProfileId(apiWallet.profiles[0]) || "",
id: apiWallet.userId || getProfileId(apiWallet.profiles[0]) || "",
linkedAccounts: apiWallet.profiles.map((profile) => {
// Create details object based on the profile data
let details:
Expand Down Expand Up @@ -105,6 +105,9 @@ export async function searchUsers(
case "externalWallet":
queryParams.externalWalletAddress = query;
break;
case "userId":
queryParams.userId = query;
break;
}

// Use the generated API function with Bearer authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export type SearchType =
| "phone"
| "id"
| "address"
| "externalWallet";
| "externalWallet"
| "userId";
4 changes: 2 additions & 2 deletions apps/dashboard/src/@/hooks/useEmbeddedWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ const fetchAccountList = ({
};
};

// Transform API response to match existing WalletUser format
// Transform API response to match the wallet user format
function transformToWalletUser(apiWallet: APIWallet): WalletUser {
return {
id: getProfileId(apiWallet.profiles[0]) || "",
id: apiWallet.userId || getProfileId(apiWallet.profiles[0]) || "",
linkedAccounts: apiWallet.profiles.map((profile) => {
// Create details object based on the profile data
let details:
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/client/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export const initiateAuthentication = <ThrowOnError extends boolean = false>(
* - `isNewUser` - Whether this is a new wallet creation
* - `token` - JWT token for authenticated API requests
* - `type` - The authentication method used
* - `userId` - Unique identifier for the authenticated user
* - `walletAddress` - Your new or existing wallet address
*
* **Next step - Verify your token:**
Expand Down Expand Up @@ -442,6 +443,7 @@ export const socialAuthentication = <ThrowOnError extends boolean = false>(
* Retrieve the authenticated user's wallet information including wallet addresses and linked authentication wallets. This endpoint provides comprehensive user data for the currently authenticated session.
*
* **Returns:**
* - userId - Unique identifier for this wallet in thirdweb auth
* - Primary wallet address
* - Smart wallet address (if available)
* - Wallet creation timestamp
Expand Down
Loading
Loading