# Nextjs-auth0: How to get app\_metadata properties from session object in afterCallback()

**URL:** <https://community.auth0.com/t/nextjs-auth0-how-to-get-app-metadata-properties-from-session-object-in-aftercallback/59667>\
**Category:** Get Help\
**Created:** [March 18, 2021, 5:59pm UTC](https://community.auth0.com/t/nextjs-auth0-how-to-get-app-metadata-properties-from-session-object-in-aftercallback/59667 "2021-03-18T17:59:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaarheed](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/zaarheed/32/28271_2.png) [@zaarheed](https://community.auth0.com/u/zaarheed)\
**Post date:** [March 18, 2021, 5:59pm UTC](https://community.auth0.com/t/nextjs-auth0-how-to-get-app-metadata-properties-from-session-object-in-aftercallback/59667/1 "2021-03-18T17:59:17Z")

</div>

**SDK:** @auth0/nextjs-auth0  
**Version:** v1.2.0

Hi all,

First time user of Auth0 and Next.js here so excuse any oversight in my question below.

I want to add two custom properties (I think they’re called claims in the auth world) to each user. These properties essentially represent the User profile type and a particular resource they have access to.

I’ve added the two properties under app\_metadata from the Auth0 dashboard and am using Passwordless Email login using a code.

Now, in Next.js I want to intercept the callback when a user logs in successfully and redirect them to the correct private page based on their profile type and the resource they have access to.

In the afterCallback() function within api/auth/[…auth0].js file in my Next.js project I have the following code:

```
import { handleAuth, handleCallback } from "@auth0/nextjs-auth0";

const afterCallback = async (req, res, session, state) => {
    console.log(session);
    return session;
}

export default handleAuth({
    async callback(req, res) {
        try {
            await handleCallback(req, res, { afterCallback });
        } catch (error) {
            res.status(error.status || 500).end(error.message);
        }
    }
});

```

However, the user property in the session object I am logging in the code above only contains what i understand to be the default properties of a JWT token.

What is the best way for me to add profileType and resourceId to this object so that I can do a check and redirect the user to the correct page?

I know it must be possible because the docs for AfterCallback use a isAdmin property in the example: [handlers/callback | @auth0/nextjs-auth0](https://auth0.github.io/nextjs-auth0/modules/handlers_callback.html#aftercallback)

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [March 19, 2021, 5:25pm UTC](https://community.auth0.com/t/nextjs-auth0-how-to-get-app-metadata-properties-from-session-object-in-aftercallback/59667/3 "2021-03-19T17:25:50Z")

</div>

Hi @zaarheed,

Welcome to the Community!

You can add custom claims such as a property in a user’s `app_metadata` to the ID Token using a [rule](https://auth0.com/docs/rules):

```auto
function(user, context, callback) {
  const namespace = 'https://myapp.example.com/';
  context.idToken[namespace + 'preferred_contact'] = user.user_metadata.preferred_contact;
  callback(null, user, context);
}

```

Your app will then have access to the custom claim in the ID Token.

> **[Sample Use Cases: Scopes and Claims](https://auth0.com/docs/get-started/apis/scopes/sample-use-cases-scopes-and-claims)**
>
> Learn how to use scopes and claims with applications and APIs.

Let me know if you have additional questions for setting this up!

---

<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:** [April 3, 2021, 5:26pm UTC](https://community.auth0.com/t/nextjs-auth0-how-to-get-app-metadata-properties-from-session-object-in-aftercallback/59667/4 "2021-04-03T17:26:52Z")

</div>

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