Skip to content

fix(auth): fix "Invalid API key" error after clearing browser storage - #83

Merged
Opaismoe merged 2 commits into
mainfrom
fix/auth-guard-session-cookie
Jun 9, 2026
Merged

fix(auth): fix "Invalid API key" error after clearing browser storage#83
Opaismoe merged 2 commits into
mainfrom
fix/auth-guard-session-cookie

Conversation

@Opaismoe

@Opaismoe Opaismoe commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • After clearing localStorage + cookies, the / route loader fired unauthenticated requests that threw UnauthorizedError("Invalid API key"), which TanStack Router surfaced as an error in the UI
  • Even after logging back in via session cookie, all route loaders (admin, groups, groups/$name, history, history/$id) skipped data loading because their guards checked getApiKey() (localStorage), which was still null

Fix

Added isAuthenticated() to api.ts — returns true if an API key is in localStorage or the pc_csrf session cookie is present (JS-readable since httpOnly: false). Replaced all six route loader guards and three enabled query flags with this check.

Test plan

  • Clear localStorage, cookies, and cache — load the app — should show login modal, no error banner
  • Log in via username/password — all pages (dashboard, groups, history, admin) should load data correctly
  • API key auth path still works (API key in localStorage, no session cookie)

🤖 Generated with Claude Code

Opaismoe and others added 2 commits June 9, 2026 11:14
…ion cookie support

Route loaders and query enabled-flags all checked getApiKey() (localStorage),
so clearing localStorage + cookies caused the index loader to fire unauthenticated
requests and throw UnauthorizedError("Invalid API key"). After logging in via
session cookie, loaders still skipped because getApiKey() returned null.

Adds isAuthenticated() that returns true when either an API key is stored in
localStorage or the pc_csrf session cookie is present, and replaces all six
route loader guards and three query enabled flags with this check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Opaismoe
Opaismoe merged commit ed5ea6c into main Jun 9, 2026
1 check passed
@Opaismoe
Opaismoe deleted the fix/auth-guard-session-cookie branch June 9, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant