Skip to content

Commit 7de273c

Browse files
committed
Dashboard: Reset last-used-* cookies on login page (#7005)
<!-- ## 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 focuses on adding a `deleteCookie` function to manage cookies and incorporates a new component, `ResetLastUsedCookies`, in the `LoginPage` to clear specific cookies upon rendering. ### Detailed summary - Added `deleteCookie` function in `cookie.ts` to delete cookies by name. - Imported constants `LAST_USED_PROJECT_ID`, `LAST_USED_TEAM_ID`, and `LAST_VISITED_TEAM_PAGE_PATH` in `LoginPage.tsx`. - Implemented `ResetLastUsedCookies` component to delete specific cookies on mount. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 95cc441 commit 7de273c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ import {
2020
useActiveWalletConnectionStatus,
2121
} from "thirdweb/react";
2222
import { createWallet, inAppWallet } from "thirdweb/wallets";
23+
import {
24+
LAST_USED_PROJECT_ID,
25+
LAST_USED_TEAM_ID,
26+
} from "../../../constants/cookies";
27+
import { deleteCookie } from "../../../lib/cookie";
2328
import { ThirdwebMiniLogo } from "../components/ThirdwebMiniLogo";
2429
import { getSDKTheme } from "../components/sdk-component-theme";
30+
import { LAST_VISITED_TEAM_PAGE_PATH } from "../team/components/last-visited-page/consts";
2531
import { doLogin, doLogout, getLoginPayload, isLoggedIn } from "./auth-actions";
2632
import { isAccountOnboardingComplete } from "./onboarding/isOnboardingRequired";
2733

@@ -116,6 +122,8 @@ export function LoginAndOnboardingPage(props: {
116122
redirectPath={props.redirectPath}
117123
loginWithInAppWallet={props.loginWithInAppWallet}
118124
/>
125+
126+
<ResetLastUsedCookies />
119127
</div>
120128
);
121129
}
@@ -139,6 +147,16 @@ function LoginPageContainer(props: {
139147
);
140148
}
141149

150+
function ResetLastUsedCookies() {
151+
// eslint-disable-next-line no-restricted-syntax
152+
useEffect(() => {
153+
deleteCookie(LAST_USED_PROJECT_ID);
154+
deleteCookie(LAST_USED_TEAM_ID);
155+
deleteCookie(LAST_VISITED_TEAM_PAGE_PATH);
156+
}, []);
157+
return null;
158+
}
159+
142160
function LoginAndOnboardingPageContent(props: {
143161
redirectPath: string;
144162
account: Account | undefined;

apps/dashboard/src/lib/cookie.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ export function setCookie(name: string, value: string, days = 365) {
2323
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
2424
document.cookie = `${name}=${value};path=/;expires=${date.toUTCString()}`;
2525
}
26+
27+
export function deleteCookie(name: string) {
28+
document.cookie = `${name}=;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT`;
29+
}

0 commit comments

Comments
 (0)