Skip to content

Commit ceeae69

Browse files
committed
Fix APIKey fetch in project layout
1 parent 37d62e2 commit ceeae69

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

apps/dashboard/src/app/api/lib/getAPIKeys.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export async function getAPIKey(apiKeyId: string) {
3737

3838
export async function getApiKeys() {
3939
const authToken = getAuthToken();
40+
4041
const res = await fetch(`${API_SERVER_URL}/v1/keys`, {
4142
method: "GET",
42-
4343
headers: {
4444
"Content-Type": "application/json",
4545
Authorization: `Bearer ${authToken}`,
@@ -53,3 +53,11 @@ export async function getApiKeys() {
5353

5454
return json.data as ApiKey[];
5555
}
56+
57+
export function getAPIKeyForProjectId(projectId: string) {
58+
if (projectId.startsWith("prj_")) {
59+
return getAPIKey(projectId.slice("prj_".length));
60+
}
61+
62+
return getAPIKey(projectId);
63+
}

apps/dashboard/src/app/team/[team_slug]/[project_slug]/connect/account-abstraction/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getProject } from "@/api/projects";
22
import { ChakraProviderSetup } from "@/components/ChakraProviderSetup";
33
import { notFound } from "next/navigation";
4-
import { getAPIKey } from "../../../../../api/lib/getAPIKeys";
4+
import { getAPIKeyForProjectId } from "../../../../../api/lib/getAPIKeys";
55
import { AccountAbstractionPage } from "./AccountAbstractionPage";
66

77
export default async function Page(props: {
@@ -14,8 +14,7 @@ export default async function Page(props: {
1414
notFound();
1515
}
1616

17-
// THIS IS A WORKAROUND - project does not have `services` info - so we fetch APIKey object.
18-
const apiKey = await getAPIKey(project.id);
17+
const apiKey = await getAPIKeyForProjectId(project.id);
1918

2019
if (!apiKey) {
2120
notFound();

apps/dashboard/src/app/team/[team_slug]/[project_slug]/settings/account-abstraction/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getProject } from "@/api/projects";
22
import { ChakraProviderSetup } from "@/components/ChakraProviderSetup";
33
import { notFound } from "next/navigation";
44
import { AccountAbstractionSettingsPage } from "../../../../../../components/smart-wallets/SponsorshipPolicies";
5-
import { getAPIKey } from "../../../../../api/lib/getAPIKeys";
5+
import { getAPIKeyForProjectId } from "../../../../../api/lib/getAPIKeys";
66

77
export default async function Page(props: {
88
params: { team_slug: string; project_slug: string };
@@ -14,8 +14,7 @@ export default async function Page(props: {
1414
notFound();
1515
}
1616

17-
// THIS IS A WORKAROUND - project does not have `services` info - so we fetch APIKey object.
18-
const apiKey = await getAPIKey(project.id);
17+
const apiKey = await getAPIKeyForProjectId(project.id);
1918

2019
if (!apiKey) {
2120
notFound();

apps/dashboard/src/app/team/[team_slug]/[project_slug]/settings/in-app-wallets/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getProject } from "@/api/projects";
22
import { notFound } from "next/navigation";
33
import { InAppWalletSettingsPage } from "../../../../../../components/embedded-wallets/Configure";
4-
import { getAPIKey } from "../../../../../api/lib/getAPIKeys";
4+
import { getAPIKeyForProjectId } from "../../../../../api/lib/getAPIKeys";
55

66
export default async function Page(props: {
77
params: { team_slug: string; project_slug: string };
@@ -13,8 +13,7 @@ export default async function Page(props: {
1313
notFound();
1414
}
1515

16-
// THIS IS A WORKAROUND - project does not have `services` info - so we fetch APIKey object.
17-
const apiKey = await getAPIKey(project.id);
16+
const apiKey = await getAPIKeyForProjectId(project.id);
1817

1918
if (!apiKey) {
2019
notFound();

apps/dashboard/src/app/team/[team_slug]/[project_slug]/settings/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getProject } from "@/api/projects";
22
import { notFound } from "next/navigation";
3-
import { getAPIKey } from "../../../../api/lib/getAPIKeys";
3+
import { getAPIKeyForProjectId } from "../../../../api/lib/getAPIKeys";
44
import { ProjectGeneralSettingsPageForTeams } from "./ProjectGeneralSettingsPageForTeams";
55

66
export default async function Page(props: {
@@ -13,8 +13,7 @@ export default async function Page(props: {
1313
notFound();
1414
}
1515

16-
// THIS IS A WORKAROUND - project does not have `services` info - so we fetch APIKey object.
17-
const apiKey = await getAPIKey(project.id);
16+
const apiKey = await getAPIKeyForProjectId(project.id);
1817

1918
if (!apiKey) {
2019
notFound();

apps/dashboard/src/app/team/[team_slug]/[project_slug]/settings/pay/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getProject } from "@/api/projects";
22
import { notFound } from "next/navigation";
33
import { PayConfig } from "../../../../../../components/pay/PayConfig";
4-
import { getAPIKey } from "../../../../../api/lib/getAPIKeys";
4+
import { getAPIKeyForProjectId } from "../../../../../api/lib/getAPIKeys";
55

66
export default async function Page(props: {
77
params: {
@@ -16,8 +16,7 @@ export default async function Page(props: {
1616
notFound();
1717
}
1818

19-
// THIS IS A WORKAROUND - project does not have `services` info - so we fetch APIKey object.
20-
const apiKey = await getAPIKey(project.id);
19+
const apiKey = await getAPIKeyForProjectId(project.id);
2120

2221
if (!apiKey) {
2322
notFound();

0 commit comments

Comments
 (0)