Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
25 replies
KingKorai

How to refetch data after Clerk login?

<SignInButton>
  <button>
    Sign in
  </button>
</SignInButton>

Problem: data is stale after authentication change.
I need a way to invalidate data (tRPC) after login/logout. Clerk doesn't seem to give you a way to manually control login-logout. They give you prebuilt SignInButton/SignOutButton but you can't control it.
I tried using useEffect with {isSignIn} = useUser() but it only worked with sign-out and not sign-in.
Solution
Update your middleware matcher

export const config = {
  matcher: [
    /*
     * Match all request paths except for the ones starting with:
     * - _next
     * - static (static files)
     * - favicon.ico (favicon file)
     */
    "/(.*?trpc.*?|(?!static|.*\\..*|_next|favicon.ico).*)",
    "/"
  ],
};
Was this page helpful?