Skip to content

Fix updateTag in migrateChatUser by moving cache invalidation to a Server Action#213

Merged
na-trium-144 merged 1 commit intomainfrom
copilot/update-chat-user-migration
Apr 3, 2026
Merged

Fix updateTag in migrateChatUser by moving cache invalidation to a Server Action#213
na-trium-144 merged 1 commit intomainfrom
copilot/update-chat-user-migration

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

updateTag (Next.js 16) is only valid inside Server Actions, but migrateChatUser was called from auth.ts's onLinkAccount callback — not a Server Action — causing a runtime error on sign-in.

Changes

chatHistory.tsmigrateChatUser

  • Stripped to DB-only: updates userId on all chat rows, nothing more.
  • Removed getPagesList import (no longer needed here).

app/actions/clearUserCache.ts (new)

  • Server Action that resolves the current user via initContext() and invalidates all their page cache keys via updateTag + Cloudflare cache.

app/clear-cache/page.tsx (new)

  • Thin client page (/clear-cache?redirect=<path>) that calls clearUserCacheAction() on mount, then redirects to the original page (redirect is validated to be relative to prevent open redirect).

accountMenu.tsx

  • Sign-in callbackURL changed from pathname/clear-cache?redirect=<pathname>, routing post-OAuth through the cache-clear page before returning the user.
  • Both sign-out handlers: window.location.reload()router.refresh().
// Before
authClient.signIn.social({ provider: "github", callbackURL: pathname });

// After
authClient.signIn.social({
  provider: "github",
  callbackURL: `/clear-cache?redirect=${encodeURIComponent(pathname)}`,
});

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
my-code 22cd93c Commit Preview URL

Branch Preview URL
Apr 03 2026, 02:27 PM

@na-trium-144 na-trium-144 marked this pull request as ready for review April 3, 2026 15:31
@na-trium-144 na-trium-144 merged commit 51196ce into main Apr 3, 2026
9 checks passed
@na-trium-144 na-trium-144 deleted the copilot/update-chat-user-migration branch April 3, 2026 15:39
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.

2 participants