Custom Claims Added to the ID Token Are Not Available in `session.user` of Auth0 NextJS SDK
Last Updated:
Overview
This article addresses an issue where custom claims added to an ID token via a post-login action are present in the issued ID token, but these custom claims are not available in the session.user object of the Auth0 NextJS Software Development Kit (SDK).
Applies To
-
Auth0 NextJS SDK
-
Custom claims
-
ID token
-
Post-login action
-
session.userobject
Cause
By default, the claims in the ID token are filtered, and only standard claims are stored in the session.user object. For more details, see the Auth0 Next.js source code on GitHub.
Solution
Use the beforeSessionSaved hook provided by the Auth0 NextJS SDK to filter the claims to add to the session.user object. Refer to the Auth0 Next.js examples on GitHub for implementation details.