From 7ab79dc3bb07b38c53134bc38459f2c8701d2162 Mon Sep 17 00:00:00 2001 From: MananTank Date: Thu, 5 Jun 2025 14:07:42 +0000 Subject: [PATCH] Dashboard: Fix contract deploy page missing last used teamId in client object (#7285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR focuses on updating the authentication mechanism by replacing the usage of `getAuthToken` with `getUserThirdwebClient` in the `page.tsx` and `uri-based-deploy.tsx` files, enhancing the handling of third-party client connections. ### Detailed summary - Removed `getAuthToken` and its associated logic in `page.tsx`. - Introduced `getUserThirdwebClient` to fetch the client in `page.tsx`. - Updated the `isLoggedIn` prop in `PublishedContract` to use `!!account`. - Adjusted the logic in `uri-based-deploy.tsx` to fetch client and teams without `authToken`. - Changed the `isLoggedIn` prop to always be `true` in `uri-based-deploy.tsx`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit - **Refactor** - Streamlined the process for obtaining the user client, simplifying authentication and client initialization for published contract and deploy flows. - Improved logic for login checks and client handling, reducing redundant token fetching and making the login state determination more straightforward. --- .../[contract_id]/[version]/page.tsx | 14 ++++++-------- .../components/uri-based-deploy.tsx | 19 +++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/apps/dashboard/src/app/(app)/(dashboard)/published-contract/[publisher]/[contract_id]/[version]/page.tsx b/apps/dashboard/src/app/(app)/(dashboard)/published-contract/[publisher]/[contract_id]/[version]/page.tsx index a2a4a2f34a7..d58b296790c 100644 --- a/apps/dashboard/src/app/(app)/(dashboard)/published-contract/[publisher]/[contract_id]/[version]/page.tsx +++ b/apps/dashboard/src/app/(app)/(dashboard)/published-contract/[publisher]/[contract_id]/[version]/page.tsx @@ -1,6 +1,5 @@ import { ChakraProviderSetup } from "@/components/ChakraProviderSetup"; import { Separator } from "@/components/ui/separator"; -import { getClientThirdwebClient } from "@/constants/thirdweb-client.client"; import { serverThirdwebClient } from "@/constants/thirdweb-client.server"; import { SimpleGrid } from "@chakra-ui/react"; import { fetchPublishedContractVersions } from "components/contract-components/fetch-contracts-with-versions"; @@ -9,7 +8,7 @@ import { notFound } from "next/navigation"; import { isAddress } from "thirdweb"; import { resolveAddress } from "thirdweb/extensions/ens"; import { getRawAccount } from "../../../../../account/settings/getAccount"; -import { getAuthToken } from "../../../../../api/lib/getAuthToken"; +import { getUserThirdwebClient } from "../../../../../api/lib/getAuthToken"; import { PublishedActions } from "../../../components/contract-actions-published.client"; import { DeployContractHeader } from "../../../components/contract-header"; @@ -68,9 +67,11 @@ export default async function PublishedContractPage( return notFound(); } - const [authToken, account] = await Promise.all([ - getAuthToken(), + const [account, client] = await Promise.all([ getRawAccount(), + getUserThirdwebClient({ + teamId: undefined, + }), ]); return ( @@ -92,10 +93,7 @@ export default async function PublishedContractPage( diff --git a/apps/dashboard/src/app/(app)/(dashboard)/published-contract/components/uri-based-deploy.tsx b/apps/dashboard/src/app/(app)/(dashboard)/published-contract/components/uri-based-deploy.tsx index 7d230f777f4..b2df8c2f09e 100644 --- a/apps/dashboard/src/app/(app)/(dashboard)/published-contract/components/uri-based-deploy.tsx +++ b/apps/dashboard/src/app/(app)/(dashboard)/published-contract/components/uri-based-deploy.tsx @@ -1,10 +1,9 @@ import { getProjects } from "@/api/projects"; import { getTeams } from "@/api/team"; import { ChakraProviderSetup } from "@/components/ChakraProviderSetup"; -import { getClientThirdwebClient } from "@/constants/thirdweb-client.client"; import { CustomContractForm } from "components/contract-components/contract-deploy-form/custom-contract"; import type { FetchDeployMetadataResult } from "thirdweb/contract"; -import { getAuthToken } from "../../../api/lib/getAuthToken"; +import { getUserThirdwebClient } from "../../../api/lib/getAuthToken"; import { loginRedirect } from "../../../login/loginRedirect"; type DeployFormForUriProps = { @@ -21,9 +20,14 @@ export async function DeployFormForUri(props: DeployFormForUriProps) { return
Could not fetch metadata
; } - const [authToken, teams] = await Promise.all([getAuthToken(), getTeams()]); + const [teams, client] = await Promise.all([ + getTeams(), + getUserThirdwebClient({ + teamId: undefined, + }), + ]); - if (!teams || !authToken) { + if (!teams) { loginRedirect(pathname); } @@ -43,11 +47,6 @@ export async function DeployFormForUri(props: DeployFormForUriProps) { })), ); - const client = getClientThirdwebClient({ - jwt: authToken, - teamId: undefined, - }); - // TODO: remove the `ChakraProviderSetup` wrapper once the form is updated to no longer use chakra return ( @@ -55,7 +54,7 @@ export async function DeployFormForUri(props: DeployFormForUriProps) { metadata={contractMetadata} metadataNoFee={contractMetadataNoFee} modules={modules?.filter((m) => m !== null)} - isLoggedIn={!!authToken} + isLoggedIn={true} teamsAndProjects={teamsAndProjects} client={client} />