Skip to content

feat: clear localStorage when logout#2446

Merged
wilsonrivera merged 9 commits intomainfrom
wilson/eng-8605-wun-q425-09-logging-out-does-not-clear-cookies-and-local
Jan 27, 2026
Merged

feat: clear localStorage when logout#2446
wilsonrivera merged 9 commits intomainfrom
wilson/eng-8605-wun-q425-09-logging-out-does-not-clear-cookies-and-local

Conversation

@wilsonrivera
Copy link
Copy Markdown
Contributor

@wilsonrivera wilsonrivera commented Jan 9, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Tracking now reliably resets on logout.
    • Logout clears cached session data from local storage.
    • Logout behavior is consistent across desktop and mobile menus, ensuring cleanup and reset always run.
  • Chores

    • Reduced a third-party tracking integration to improve privacy and simplify tracking behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 9, 2026

Walkthrough

Adds logout cleanup by clearing specific localStorage keys and resetting tracking via a new LogoutLink component; removes Koala integration and all Koala-related calls from the tracking module.

Changes

Cohort / File(s) Summary
Logout & localStorage cleanup
studio/src/components/user-menu.tsx
Adds a list of localStorage keys and removeLocalStorageItems; introduces a LogoutLink component (uses PropsWithChildren) that wraps Next.js Link, runs localStorage cleanup and calls tracking reset on click; replaces previous inline logout Links in UserMenu and UserMenuMobile with LogoutLink.
Tracking integration cleanup
studio/src/lib/track.ts
Removes Koala integration and all Koala-related calls (identify/reset) from the tracking utilities; retains Reo and PostHog logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: clearing localStorage on logout, which aligns with the changeset modifications in user-menu.tsx and track.ts.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 1.49%. Comparing base (05dafc9) to head (77fc34b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
studio/src/components/user-menu.tsx 0.00% 34 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #2446      +/-   ##
========================================
- Coverage   1.49%   1.49%   -0.01%     
========================================
  Files        292     292              
  Lines      46968   46983      +15     
  Branches     431     431              
========================================
  Hits         703     703              
- Misses     45982   45997      +15     
  Partials     283     283              
Files with missing lines Coverage Δ
studio/src/lib/track.ts 0.00% <ø> (ø)
studio/src/components/user-menu.tsx 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @studio/src/components/user-menu.tsx:
- Around line 112-114: The DropdownMenuItem should use Radix's asChild
composition instead of being wrapped by Link to avoid event conflicts; update
the instances where a Link component (e.g., LogoutLink and the other
Login/Account link earlier) currently wrap DropdownMenuItem so that
DropdownMenuItem receives the asChild prop and the Link is rendered inside it
(i.e., change from
<LogoutLink><DropdownMenuItem>…</DropdownMenuItem></LogoutLink> to using
DropdownMenuItem asChild with <LogoutLink> as its child), keeping the same
labels and props.

In @studio/src/lib/track.ts:
- Line 20: The code was only referencing the reset property (window.ko?.reset)
instead of invoking it; change the call to execute the function by using
window.ko?.reset() so the Koala reset runs when available (keep the optional
chaining as shown).
🧹 Nitpick comments (2)
studio/src/components/user-menu.tsx (2)

29-38: Remove or replace the debug console.log statement.

Line 35 logs each removed key to the console. This appears to be debug code that should either be removed before production or replaced with a proper logging mechanism if diagnostics are needed.

🧹 Proposed cleanup
  for (const key of localStorageKeysToRemove) {
-   console.log(key);
    window.localStorage.removeItem(key);
  }

40-52: Consider adding error handling for cleanup operations.

The onClick handler calls removeLocalStorageItems() and resetTracking() without error handling. If either operation throws an exception, the logout navigation could be interrupted. Consider wrapping these calls in a try-catch block to ensure logout proceeds even if cleanup fails.

🛡️ Proposed defensive handling
  <Link
    onClick={() => {
-     removeLocalStorageItems();
-     resetTracking();
+     try {
+       removeLocalStorageItems();
+       resetTracking();
+     } catch (error) {
+       console.error('Failed to clear user data on logout:', error);
+       // Allow logout to proceed regardless
+     }
    }}
    href={process.env.NEXT_PUBLIC_COSMO_CP_URL + "/v1/auth/logout"}
  >
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7bb0be1 and 4d821f5.

📒 Files selected for processing (2)
  • studio/src/components/user-menu.tsx
  • studio/src/lib/track.ts
🧰 Additional context used
🧬 Code graph analysis (1)
studio/src/components/user-menu.tsx (2)
studio/src/lib/track.ts (1)
  • resetTracking (76-76)
studio/src/components/ui/dropdown-menu.tsx (1)
  • DropdownMenuItem (206-206)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build_test
  • GitHub Check: build_push_image
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
studio/src/components/user-menu.tsx (2)

14-27: LGTM: Import and localStorage keys defined appropriately.

The PropsWithChildren import is correctly used for the LogoutLink component, and the array of localStorage keys targets GraphiQL and Playground-related state that should be cleared on logout.


63-63: Fix nested interactive elements causing accessibility violation.

Nesting <LogoutLink> (which renders a <Link>) inside a <Button> creates invalid HTML and breaks accessibility. Interactive elements should not be nested. This causes issues with screen readers, keyboard navigation, and event handling.

♿ Proposed fix

Replace the Button wrapping the LogoutLink with the Button's styling applied directly to the LogoutLink:

-     <Button>
-       <LogoutLink />
-     </Button>
+     <LogoutLink>
+       <Button asChild>Logout</Button>
+     </LogoutLink>

Or alternatively, if Button supports asChild pattern, apply the button styling to the Link:

-     <Button>
-       <LogoutLink />
-     </Button>
+     <Button asChild>
+       <LogoutLink />
+     </Button>

Likely an incorrect or invalid review comment.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@studio/src/components/user-menu.tsx`:
- Around line 61-63: The Button wrapper currently contains LogoutLink (which
renders an <a>), causing invalid nested interactive elements; update the usage
so the link is the interactive element: either use the Button component's
asChild prop (if available) and render LogoutLink as the child (ensure
LogoutLink forwards refs and accepts className/props), or remove the Button
wrapper and apply Button's styles/classes directly to LogoutLink; change the JSX
around Button and LogoutLink accordingly and adjust LogoutLink to forwardRef and
accept extra props when using asChild.
♻️ Duplicate comments (1)
studio/src/components/user-menu.tsx (1)

111-113: Use asChild prop for proper Link composition with DropdownMenuItem.

This wraps DropdownMenuItem inside LogoutLink (a Link component), which causes event handling conflicts. The Radix UI dropdown menu primitive supports the asChild prop for proper composition.

Suggested fix
-        <LogoutLink>
-          <DropdownMenuItem>Logout</DropdownMenuItem>
-        </LogoutLink>
+        <DropdownMenuItem asChild>
+          <LogoutLink>Logout</LogoutLink>
+        </DropdownMenuItem>

Note: LogoutLink will need to forward refs for this pattern to work correctly:

const LogoutLink = React.forwardRef<HTMLAnchorElement, PropsWithChildren<{ className?: string }>>(
  ({ children, ...props }, ref) => {
    return (
      <Link
        ref={ref}
        onClick={() => {
          removeLocalStorageItems();
          resetTracking();
        }}
        href={process.env.NEXT_PUBLIC_COSMO_CP_URL + "/v1/auth/logout"}
        {...props}
      >
        {children || "Logout"}
      </Link>
    );
  }
);
LogoutLink.displayName = "LogoutLink";

Copy link
Copy Markdown
Contributor

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wilsonrivera wilsonrivera merged commit cf76d6f into main Jan 27, 2026
11 checks passed
@wilsonrivera wilsonrivera deleted the wilson/eng-8605-wun-q425-09-logging-out-does-not-clear-cookies-and-local branch January 27, 2026 13:51
maxbol pushed a commit to maxbol/cosmo that referenced this pull request Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants