Skip to content

Commit e4ec8df

Browse files
committed
feat: do onboarding if not done yet
1 parent 13a31de commit e4ec8df

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

apps/dashboard/src/app/login/page.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { useTheme } from "next-themes";
77
import { useSearchParams } from "next/navigation";
88
import { Suspense, useEffect, useState } from "react";
99
import { ConnectEmbed } from "thirdweb/react";
10-
import { getProfiles } from "thirdweb/wallets";
1110
import { getCookie } from "../../stores/SyncStoreToCookies";
1211
import { ThirdwebMiniLogo } from "../components/ThirdwebMiniLogo";
1312
import { getSDKTheme } from "../components/sdk-component-theme";
1413
import { doLogin, doLogout, getLoginPayload, isLoggedIn } from "./auth-actions";
14+
import { getAccountPreferences } from "lib/onboarding";
15+
import { useAccount } from "@3rdweb-sdk/react/hooks/useApi";
1516

1617
export default function LoginPage() {
1718
return (
@@ -45,19 +46,29 @@ function CustomConnectEmmbed() {
4546
const { theme } = useTheme();
4647
const nextSearchParam = searchParams?.get("next");
4748
const client = useThirdwebClient();
49+
const accountQuery = useAccount();
4850

4951
async function onLoginSuccessful() {
50-
const profiles = await getProfiles({ client });
5152
if (nextSearchParam && isValidRedirectPath(nextSearchParam)) {
5253
router.replace(nextSearchParam);
5354
} else {
5455
const dashboardType = getCookie("x-dashboard-type");
56+
const account = await accountQuery.refetch();
57+
if (!account.data) throw new Error("No account found.");
58+
const existingAccountPreferences = await getAccountPreferences({
59+
accountId: account.data.id,
60+
});
61+
62+
if (!existingAccountPreferences) {
63+
router.replace(
64+
`/onboarding?${account.data.email ? `email=${account.data.email}` : ""}`,
65+
);
66+
}
67+
5568
if (dashboardType === "team") {
5669
router.replace("/team");
5770
} else {
58-
router.replace(
59-
`/onboarding?${profiles[0] ? `email=${profiles[0].details.email}` : ""}`,
60-
);
71+
router.replace("/dashboard");
6172
}
6273
}
6374
}

apps/dashboard/src/app/onboarding/page.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
type UseFormRegister,
3131
useForm,
3232
} from "react-hook-form";
33+
import { getCookie } from "stores/SyncStoreToCookies";
3334
import { Blobbie } from "thirdweb/react";
3435
import { shortenAddress } from "thirdweb/utils";
3536
import { FormErrorMessage, FormLabel } from "tw-components";
@@ -71,7 +72,6 @@ export default function OnboardingPage({
7172
searchParams,
7273
}: { searchParams: { address: string; email: string | undefined } }) {
7374
const accountQuery = useAccount();
74-
console.log(searchParams.email);
7575
const [step, setStep] = useState(searchParams.email ? 2 : 1);
7676
const [direction, setDirection] = useState(1);
7777
const router = useRouter();
@@ -116,7 +116,12 @@ export default function OnboardingPage({
116116
throw new Error(json.message);
117117
}
118118

119-
router.push("/dashboard");
119+
const dashboardType = getCookie("x-dashboard-type");
120+
if (dashboardType === "team") {
121+
router.push("/team");
122+
} else {
123+
router.push("/dashboard");
124+
}
120125
};
121126

122127
const watchInterests = watch("interests");
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { THIRDWEB_ANALYTICS_API_HOST } from "constants/urls";
2+
3+
export async function getAccountPreferences(args: {
4+
accountId: string;
5+
}) {
6+
const { accountId } = args;
7+
8+
const res = await fetch(
9+
`${THIRDWEB_ANALYTICS_API_HOST}/v1/preferences/account/${accountId}`,
10+
{
11+
method: "GET",
12+
headers: {
13+
"Content-Type": "application/json",
14+
},
15+
},
16+
);
17+
const json = await res.json();
18+
19+
if (res.status !== 200) {
20+
if (res.status === 404) {
21+
return null;
22+
}
23+
throw new Error(json.message);
24+
}
25+
26+
return json.data;
27+
}

0 commit comments

Comments
 (0)