Windvexer
Windvexer

Reputation: 1

Clerk Public Metadata Update Delay in Middleware.js with Next.js

I'm using Clerk for authentication in my Next.js app. To control access to certain routes that are protected via middleware.js, I'm updating Clerk users' publicMetadata using the JavaScript SDK.

The update itself works as expected with one exception: There's a 10-15 second delay before the updated metadata is reflected in the token (i.e. sessionClaims) when read in middleware. This causes access checks to fail (404) temporarily after the metadata is updated. In contrast, I can see the metadata changes immediately reflected in the user's data the Clerk Admin dashboard.

Question:

Has anyone else experienced this issue? Is there a way to force an immediate refresh of sessionClaims so the metadata update is immediately available in middleware.js?

Any insights or workarounds would be greatly appreciated! 🚀

Upvotes: 0

Views: 65

Answers (0)

Related Questions