Skip to content

Commit 153651d

Browse files
committed
[TOOL-3241] Fix previous account shown after logging out in onboarding flow (#6061)
1 parent 8ba460b commit 153651d

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

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

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useDashboardRouter } from "@/lib/DashboardRouter";
99
import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
1010
import { useTheme } from "next-themes";
1111
import Link from "next/link";
12-
import { Suspense, lazy, useState } from "react";
12+
import { Suspense, lazy, useEffect, useState } from "react";
1313
import { ConnectEmbed, useActiveWalletConnectionStatus } from "thirdweb/react";
1414
import { createWallet, inAppWallet } from "thirdweb/wallets";
1515
import { ClientOnly } from "../../components/ClientOnly/ClientOnly";
@@ -154,6 +154,32 @@ function PageContent(props: {
154154
router.replace(props.redirectPath);
155155
}
156156

157+
async function onLogin() {
158+
const account = await getRawAccountAction();
159+
160+
// shouldn't happen - but if account is not found, stay on login page
161+
if (!account) {
162+
return;
163+
}
164+
165+
if (!isOnboardingComplete(account)) {
166+
setScreen({
167+
id: "onboarding",
168+
account,
169+
});
170+
} else {
171+
onComplete();
172+
}
173+
}
174+
175+
// eslint-disable-next-line no-restricted-syntax
176+
useEffect(() => {
177+
// if suddenly disconnected
178+
if (connectionStatus !== "connected" && screen.id !== "login") {
179+
setScreen({ id: "login" });
180+
}
181+
}, [connectionStatus, screen.id]);
182+
157183
if (connectionStatus === "connecting") {
158184
return <LoadingCard />;
159185
}
@@ -170,29 +196,14 @@ function PageContent(props: {
170196
onComplete={onComplete}
171197
redirectPath={props.redirectPath}
172198
redirectToCheckout={redirectToCheckout}
199+
onLogout={() => {
200+
setScreen({ id: "login" });
201+
}}
173202
/>
174203
</Suspense>
175204
);
176205
}
177206

178-
async function onLogin() {
179-
const account = await getRawAccountAction();
180-
181-
// shouldn't happen - but if account is not found, stay on login page
182-
if (!account) {
183-
return;
184-
}
185-
186-
if (!isOnboardingComplete(account)) {
187-
setScreen({
188-
id: "onboarding",
189-
account,
190-
});
191-
} else {
192-
onComplete();
193-
}
194-
}
195-
196207
return <LoadingCard />;
197208
}
198209

apps/dashboard/src/app/login/onboarding/General.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@ type OnboardingGeneralProps = {
1414
account: Account;
1515
onSave: (email: string) => void;
1616
onDuplicate: (email: string) => void;
17+
onLogout: () => void;
1718
};
1819

1920
export const OnboardingGeneral: React.FC<OnboardingGeneralProps> = ({
2021
account,
2122
onSave,
2223
onDuplicate,
24+
onLogout,
2325
}) => {
2426
const [existing, setExisting] = useState(false);
2527
const activeWallet = useActiveWallet();
2628
const { disconnect } = useDisconnect();
2729

2830
async function handleLogout() {
2931
await doLogout();
32+
onLogout();
3033
if (activeWallet) {
3134
disconnect(activeWallet);
3235
}

apps/dashboard/src/app/login/onboarding/on-boarding-ui.client.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type OnboardingScreen =
2121
function OnboardingUI(props: {
2222
account: Account;
2323
onComplete: () => void;
24+
onLogout: () => void;
2425
// path to redirect from stripe
2526
redirectPath: string;
2627
redirectToCheckout: RedirectBillingCheckoutAction;
@@ -68,6 +69,7 @@ function OnboardingUI(props: {
6869
{screen.id === "onboarding" && (
6970
<OnboardingGeneral
7071
account={account}
72+
onLogout={props.onLogout}
7173
onSave={(email) => {
7274
setUpdatedEmail(email);
7375
setScreen({

0 commit comments

Comments
 (0)