# Get user meta as part of session token

**URL:** <https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [February 16, 2025, 11:39pm UTC](https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262 "2025-02-16T23:39:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris.alwin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chris.alwin/32/72972_2.png) [@chris.alwin](https://community.auth0.com/u/chris.alwin)\
**Post date:** [February 16, 2025, 11:39pm UTC](https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262/1 "2025-02-16T23:39:59Z")

</div>

Ready to post? 🔍 First, try searching for your answer.  
Hi there,

Firstly apologies if this is already answered but I am struggling to find an answer.

We have a login flow using Auth0 and part of the that is we need to get some attributes from the user when authenticated. Currently, we are making a new user in the CMS using the email, but we need more details from the `user_meta` object. How best to do this? i have tried using actions, I’m getting no change to the session. Can it be done without another API query? Can I just add to the returned authenticated session object?

Im after any help here. Ideally id just like to update the returned session data as it will only be a few fields, such as names, role. So an other API request would be overkill i feel.

Many thanks for any help.

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [February 17, 2025, 9:43pm UTC](https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262/3 "2025-02-17T21:43:12Z")

</div>

Hi @chris.alwin,

Welcome to the Auth0 Community and thank you for your post!

You are able to pass more information about a user such as **user\_metadata** to your application by using [Custom Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims) in order to add more fields to the token. This can be achieved with a Post-Login Action, as mentioned [here](https://auth0.com/docs/manage-users/user-accounts/metadata), in our documentation about metadata.

An example would be as mentioned below:

```auto
const namespace = 'https://my-app.example.com';
    api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata);

```

You can also check this [community post](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000), which references this [Knowledge Article](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000) about **Adding custom claims to tokens**.

Additionally you might also be interested in having a look over the [Authorization Extension](https://auth0.com/docs/customize/extensions/authorization-extension).

I hope this helped.  
Best regards,  
Remus

---

<div class="post-metadata">

**Author:** ![chris.alwin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chris.alwin/32/72972_2.png) [@chris.alwin](https://community.auth0.com/u/chris.alwin)\
**Post date:** [February 17, 2025, 10:39pm UTC](https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262/4 "2025-02-17T22:39:54Z")

</div>

Thankyou so much!! I am on the right path then. Is there caching on the responses? As I don’t see any changes. I can see in the logs the Action runs and the console logs out the data I want but I still just getting the same user object as part of the session response:

```auto
nickname: 'user',
    name: 'Demo User',
    picture: 'https://s.gravatar.com/avatar/221bbf03138d06df71744ceefa07cce5?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fus.png',
    email: 'user@ ***** -email.com',
    email_verified: false,
    sub: 'auth0|66c286 ****** d181fb467'

```

Log output:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/d/d/dd571dc72888075b0b42fd17e742af2cd9e95aab.png)

thanks

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [February 18, 2025, 12:21am UTC](https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262/5 "2025-02-18T00:21:20Z")

</div>

Hi @chris.alwin,

Thank you for your reply !

Generally speaking there shouldn’t be no caching involved, but this depends on the authentication as well. Since this is a post-login action, the process of setting custom claims will happen _after the user authenticates_, so _after a token was already issued_. The changes will be seen only when a new token has been generated.

Please let me know if after a new token is issued this is still the case.

Thanks,  
Remus

---

<div class="post-metadata">

**Author:** ![chris.alwin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chris.alwin/32/72972_2.png) [@chris.alwin](https://community.auth0.com/u/chris.alwin)\
**Post date:** [February 18, 2025, 12:51am UTC](https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262/6 "2025-02-18T00:51:55Z")

</div>

> [@remus.ivan](#):
>
> Please let me know if after a new token is issued th

Yeah im still not seeing any change, with different access tokens. I could be looking in the wrong place though, im referencing the session thats created not a user API endpoint. The first code snippet is the user object that is got from the session user. Ideally where i’d get the updated info.

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [February 18, 2025, 9:07pm UTC](https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262/7 "2025-02-18T21:07:15Z")

</div>

Hi @chris.alwin,

Thank you for your reply !

As it can be seen in the community post that i have mentioned earlier as well, with setting custom claims to the tokens for you can you either the [GET user info](https://auth0.com/docs/api/authentication#get-user-info) endpoint to access the metadata from the claims, but you can also decode the token using a tool such as [jwt.io](https://jwt.io/) and see all the claims within it.

Please have a look at our documentation about [JWT Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/json-web-token-claims), [Get Access Tokens](https://auth0.com/docs/secure/tokens/access-tokens/get-access-tokens) or GET an ID Token with the right scopes and claims with some sample use-cases being presented under this [documentation](https://auth0.com/docs/get-started/apis/scopes/sample-use-cases-scopes-and-claims). Additionally you can also check this [blog post](https://auth0.com/blog/adding-custom-claims-to-id-token-with-auth0-actions/).

Thanks,  
Remus

---

<div class="post-metadata">

**Author:** ![chris.alwin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chris.alwin/32/72972_2.png) [@chris.alwin](https://community.auth0.com/u/chris.alwin)\
**Post date:** [February 19, 2025, 2:52am UTC](https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262/8 "2025-02-19T02:52:49Z")

</div>

Appreciate all your help. I have found the issue and not a Auth0 or my configuration. As thats was all working as expected. It turns out using the NextJS Auth0 SDK has a filter on the session keys. So adding the beforeSessionSaved to the AuthClient setup allows me to view all the info i need. [nextjs-auth0/EXAMPLES.md at main · auth0/nextjs-auth0 · GitHub](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#beforesessionsaved)

In case anyone else comes across this. Make sure to add the documented function to the client setup for NextJS implementation.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 5, 2025, 2:53am UTC](https://community.auth0.com/t/get-user-meta-as-part-of-session-token/182262/9 "2025-03-05T02:53:10Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
