V4 NextJS SDK Does Not Return Custom Fields on User idToken

I am running into an issue described here: https://community.auth0.com/t/post-login-trigger-only-firing-for-one-application-in-my-tenant-why-not-the-others/182462

Basically, I have a custom action that is triggered post login for my tenant that serves to attach custom metadata to a user’s id token via api.idToken.setCustomClaim(). In apps using the old v3 SDK, this metadata is returned with the user object from useUser without issue. In the beta v4 SDK, this metadata is nowhere to be found.

Is there some action I need to take to ensure my metadata is attached to my idTokens in the V4 SDK or is this a bug?

Hi @relero90,

Welcome back to the Auth0 Community and thank you for your post.

In the V3 version of the NextJS Auth0 SDK any claims added to the ID token were automatically propagated to the user object. In the V4 version the list of default claims that persist in the user object does not include the metadata.

In order to ensure this metadata is passed to the ID token you can use the beforeSessionSaved hook. Please check out the V4 Migration Guide included in the NextJS SDK for further documentation.

I hope this helped.
Thanks again,
Remus