# onCallback hook in v4 "@auth0/nextjs-auth0/server"

**URL:** <https://community.auth0.com/t/oncallback-hook-in-v4-auth0-nextjs-auth0-server/182699>\
**Category:** Get Help\
**Tags:** login-prompt-new-experience, login-experience\
**Created:** [February 24, 2025, 8:34am UTC](https://community.auth0.com/t/oncallback-hook-in-v4-auth0-nextjs-auth0-server/182699 "2025-02-24T08:34:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfranco](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dfranco/32/71426_2.png) [@dfranco](https://community.auth0.com/u/dfranco)\
**Post date:** [February 24, 2025, 8:34am UTC](https://community.auth0.com/t/oncallback-hook-in-v4-auth0-nextjs-auth0-server/182699/1 "2025-02-24T08:34:24Z")

</div>

Hello, I am following [nextjs-auth0/EXAMPLES.md at main · guabu/nextjs-auth0 · GitHub](https://github.com/guabu/nextjs-auth0/blob/main/EXAMPLES.md#oncallback),

I tried console.log(context) and the only field available is returnTo, how do I set fields in the context property? can I add fields when my middleware is called before the onCallback?

```auto
export const auth0 = new Auth0Client({
  async onCallback(error, context, session) {
    // redirect the user to a custom error page
    if (error) {
      return NextResponse.redirect(
        new URL(`/error?error=${error.message}`, process.env.APP_BASE_URL)
      )
    }

    // complete the redirect to the provided returnTo URL
    return NextResponse.redirect(
      new URL(context.returnTo || "/", process.env.APP_BASE_URL)
    )
  },
})

```

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 24, 2025, 7:35pm UTC](https://community.auth0.com/t/oncallback-hook-in-v4-auth0-nextjs-auth0-server/182699/3 "2025-02-24T19:35:38Z")

</div>

Hi @dfranco,

It won’t be possible to add the `returnTo` field in the context property directly. Instead, the `returnTo` field can be appended to the login route to specify where you want to redirect your users after they complete the login successfully.

For an example, please refer to [nextjs-auth0/EXAMPLES.md at main · guabu/nextjs-auth0 · GitHub](https://github.com/guabu/nextjs-auth0/blob/main/EXAMPLES.md#the-returnto-parameter).

Thanks,  
Rueben

---

<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 10, 2025, 7:36pm UTC](https://community.auth0.com/t/oncallback-hook-in-v4-auth0-nextjs-auth0-server/182699/4 "2025-03-10T19:36:04Z")

</div>

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