Skip to content

Commit a68ec74

Browse files
committed
Dashboard: Use React taint API for envs, envs cleanup (#6992)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR primarily focuses on refactoring the environment variables used throughout the application, shifting from a centralized `env` file to a more modular `public-envs` and `server-envs` structure. This enhances organization and clarity regarding environment variable usage. ### Detailed summary - Deleted `env.ts` and introduced `public-envs.ts` and `server-envs.ts`. - Updated imports across various files to use new environment variable structure. - Replaced direct `process.env` calls with imported constants. - Added `taint` feature for sensitive server environment variables. - Adjusted fetch URLs to use `NEXT_PUBLIC_THIRDWEB_API_HOST` instead of `API_SERVER_URL`. > The following files were skipped due to too many changes: `apps/dashboard/src/@/constants/server-envs.ts`, `apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_utils/getContractPageMetadata.ts`, `apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_utils/getContractPageMetadataSetup.ts`, `apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/engine/cloud/server-wallets/components/try-it-out.tsx` > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 7ae3a81 commit a68ec74

File tree

89 files changed

+610
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+610
-414
lines changed

apps/dashboard/next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const baseNextConfig: NextConfig = {
123123
webpackBuildWorker: true,
124124
webpackMemoryOptimizations: true,
125125
serverSourceMaps: false,
126+
taint: true,
126127
},
127128
serverExternalPackages: ["pino-pretty"],
128129
async headers() {

apps/dashboard/src/@/actions/acceptInvite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use server";
22

33
import { getAuthToken } from "../../app/(app)/api/lib/getAuthToken";
4-
import { API_SERVER_URL } from "../constants/env";
4+
import { NEXT_PUBLIC_THIRDWEB_API_HOST } from "../constants/public-envs";
55

66
export async function acceptInvite(options: {
77
teamId: string;
@@ -17,7 +17,7 @@ export async function acceptInvite(options: {
1717
}
1818

1919
const res = await fetch(
20-
`${API_SERVER_URL}/v1/teams/${options.teamId}/invites/${options.inviteId}/accept`,
20+
`${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/teams/${options.teamId}/invites/${options.inviteId}/accept`,
2121
{
2222
method: "POST",
2323
headers: {

apps/dashboard/src/@/actions/billing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use server";
22

33
import { getAuthToken } from "../../app/(app)/api/lib/getAuthToken";
4-
import { API_SERVER_URL } from "../constants/env";
4+
import { NEXT_PUBLIC_THIRDWEB_API_HOST } from "../constants/public-envs";
55

66
export async function reSubscribePlan(options: {
77
teamId: string;
@@ -14,7 +14,7 @@ export async function reSubscribePlan(options: {
1414
}
1515

1616
const res = await fetch(
17-
`${API_SERVER_URL}/v1/teams/${options.teamId}/checkout/resubscribe-plan`,
17+
`${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/teams/${options.teamId}/checkout/resubscribe-plan`,
1818
{
1919
method: "PUT",
2020
headers: {

apps/dashboard/src/@/actions/confirmEmail.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use server";
22

33
import { getAuthToken } from "../../app/(app)/api/lib/getAuthToken";
4-
import { API_SERVER_URL } from "../constants/env";
4+
import { NEXT_PUBLIC_THIRDWEB_API_HOST } from "../constants/public-envs";
55

66
export async function confirmEmailWithOTP(otp: string) {
77
const token = await getAuthToken();
@@ -12,16 +12,19 @@ export async function confirmEmailWithOTP(otp: string) {
1212
};
1313
}
1414

15-
const res = await fetch(`${API_SERVER_URL}/v1/account/confirmEmail`, {
16-
method: "PUT",
17-
headers: {
18-
"Content-Type": "application/json",
19-
Authorization: `Bearer ${token}`,
15+
const res = await fetch(
16+
`${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/account/confirmEmail`,
17+
{
18+
method: "PUT",
19+
headers: {
20+
"Content-Type": "application/json",
21+
Authorization: `Bearer ${token}`,
22+
},
23+
body: JSON.stringify({
24+
confirmationToken: otp,
25+
}),
2026
},
21-
body: JSON.stringify({
22-
confirmationToken: otp,
23-
}),
24-
});
27+
);
2528

2629
if (!res.ok) {
2730
const json = await res.json();

apps/dashboard/src/@/actions/getBalancesFromMoralis.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { defineDashboardChain } from "lib/defineDashboardChain";
33
import { ZERO_ADDRESS, isAddress, toTokens } from "thirdweb";
44
import { getWalletBalance } from "thirdweb/wallets";
5+
import { MORALIS_API_KEY } from "../constants/server-envs";
56
import { serverThirdwebClient } from "../constants/thirdweb-client.server";
67

78
type BalanceQueryResponse = Array<{
@@ -60,7 +61,7 @@ export async function getTokenBalancesFromMoralis(params: {
6061
const resp = await fetch(tokenBalanceEndpoint, {
6162
method: "GET",
6263
headers: {
63-
"x-api-key": process.env.MORALIS_API_KEY || "",
64+
"x-api-key": MORALIS_API_KEY,
6465
},
6566
});
6667

apps/dashboard/src/@/actions/getWalletNFTs.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import type { WalletNFT } from "lib/wallet/nfts/types";
1212
import { getVercelEnv } from "../../lib/vercel-utils";
1313
import { isAlchemySupported } from "../../lib/wallet/nfts/isAlchemySupported";
1414
import { isMoralisSupported } from "../../lib/wallet/nfts/isMoralisSupported";
15-
import { DASHBOARD_THIRDWEB_CLIENT_ID } from "../constants/env";
15+
import { NET_PUBLIC_DASHBOARD_THIRDWEB_CLIENT_ID } from "../constants/public-envs";
16+
import { MORALIS_API_KEY } from "../constants/server-envs";
1617

1718
type WalletNFTApiReturn =
1819
| { result: WalletNFT[]; error?: undefined }
@@ -59,13 +60,13 @@ export async function getWalletNFTs(params: {
5960
}
6061
}
6162

62-
if (isMoralisSupported(chainId) && process.env.MORALIS_API_KEY) {
63+
if (isMoralisSupported(chainId) && MORALIS_API_KEY) {
6364
const url = generateMoralisUrl({ chainId, owner });
6465

6566
const response = await fetch(url, {
6667
method: "GET",
6768
headers: {
68-
"X-API-Key": process.env.MORALIS_API_KEY,
69+
"X-API-Key": MORALIS_API_KEY,
6970
},
7071
next: {
7172
revalidate: 10, // cache for 10 seconds
@@ -148,7 +149,7 @@ async function getWalletNFTsFromInsight(params: {
148149

149150
const response = await fetch(url, {
150151
headers: {
151-
"x-client-id": DASHBOARD_THIRDWEB_CLIENT_ID,
152+
"x-client-id": NET_PUBLIC_DASHBOARD_THIRDWEB_CLIENT_ID,
152153
},
153154
});
154155

apps/dashboard/src/@/actions/proxies.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
"use server";
22

33
import { getAuthToken } from "../../app/(app)/api/lib/getAuthToken";
4-
import { API_SERVER_URL, THIRDWEB_ENGINE_CLOUD_URL } from "../constants/env";
4+
import {
5+
NEXT_PUBLIC_ENGINE_CLOUD_URL,
6+
NEXT_PUBLIC_PAY_URL,
7+
NEXT_PUBLIC_THIRDWEB_API_HOST,
8+
} from "../constants/public-envs";
9+
import { ANALYTICS_SERVICE_URL } from "../constants/server-envs";
510

611
type ProxyActionParams = {
712
pathname: string;
@@ -76,22 +81,22 @@ async function proxy<T>(
7681
}
7782

7883
export async function apiServerProxy<T>(params: ProxyActionParams) {
79-
return proxy<T>(API_SERVER_URL, params);
84+
return proxy<T>(NEXT_PUBLIC_THIRDWEB_API_HOST, params);
8085
}
8186

8287
export async function engineCloudProxy<T>(params: ProxyActionParams) {
83-
return proxy<T>(THIRDWEB_ENGINE_CLOUD_URL, params);
88+
return proxy<T>(NEXT_PUBLIC_ENGINE_CLOUD_URL, params);
8489
}
8590

8691
export async function payServerProxy<T>(params: ProxyActionParams) {
8792
return proxy<T>(
88-
process.env.NEXT_PUBLIC_PAY_URL
89-
? `https://${process.env.NEXT_PUBLIC_PAY_URL}`
93+
NEXT_PUBLIC_PAY_URL
94+
? `https://${NEXT_PUBLIC_PAY_URL}`
9095
: "https://pay.thirdweb-dev.com",
9196
params,
9297
);
9398
}
9499

95100
export async function analyticsServerProxy<T>(params: ProxyActionParams) {
96-
return proxy<T>(process.env.ANALYTICS_SERVICE_URL || "", params);
101+
return proxy<T>(ANALYTICS_SERVICE_URL, params);
97102
}

apps/dashboard/src/@/actions/sendTeamInvite.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use server";
22

33
import { getAuthToken } from "../../app/(app)/api/lib/getAuthToken";
4-
import { API_SERVER_URL } from "../constants/env";
4+
import { NEXT_PUBLIC_THIRDWEB_API_HOST } from "../constants/public-envs";
55

66
export async function sendTeamInvites(options: {
77
teamId: string;
@@ -40,17 +40,20 @@ async function sendInvite(
4040
invite: { email: string; role: "OWNER" | "MEMBER" },
4141
token: string,
4242
) {
43-
const res = await fetch(`${API_SERVER_URL}/v1/teams/${teamId}/invites`, {
44-
method: "POST",
45-
headers: {
46-
Authorization: `Bearer ${token}`,
47-
"Content-Type": "application/json",
43+
const res = await fetch(
44+
`${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/teams/${teamId}/invites`,
45+
{
46+
method: "POST",
47+
headers: {
48+
Authorization: `Bearer ${token}`,
49+
"Content-Type": "application/json",
50+
},
51+
body: JSON.stringify({
52+
inviteEmail: invite.email,
53+
inviteRole: invite.role,
54+
}),
4855
},
49-
body: JSON.stringify({
50-
inviteEmail: invite.email,
51-
inviteRole: invite.role,
52-
}),
53-
});
56+
);
5457

5558
if (!res.ok) {
5659
const errorMessage = await res.text();

apps/dashboard/src/@/actions/stripe-actions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import "server-only";
22

33
import Stripe from "stripe";
44
import type { Team } from "../api/team";
5+
import { STRIPE_SECRET_KEY } from "../constants/server-envs";
56

67
let existingStripe: Stripe | undefined;
78

89
function getStripe() {
910
if (!existingStripe) {
10-
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
11-
1211
if (!STRIPE_SECRET_KEY) {
1312
throw new Error("STRIPE_SECRET_KEY is not set");
1413
}

apps/dashboard/src/@/actions/updateAccount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use server";
22
import { getAuthToken } from "../../app/(app)/api/lib/getAuthToken";
3-
import { API_SERVER_URL } from "../constants/env";
3+
import { NEXT_PUBLIC_THIRDWEB_API_HOST } from "../constants/public-envs";
44

55
export async function updateAccount(values: {
66
name?: string;
@@ -13,7 +13,7 @@ export async function updateAccount(values: {
1313
throw new Error("No Auth token");
1414
}
1515

16-
const res = await fetch(`${API_SERVER_URL}/v1/account`, {
16+
const res = await fetch(`${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/account`, {
1717
method: "PUT",
1818
headers: {
1919
"Content-Type": "application/json",

0 commit comments

Comments
 (0)