# Need help on creating a dynamic callback url

**URL:** <https://community.auth0.com/t/need-help-on-creating-a-dynamic-callback-url/99222>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, nextjs-auth0\
**Created:** [January 29, 2023, 7:51am UTC](https://community.auth0.com/t/need-help-on-creating-a-dynamic-callback-url/99222 "2023-01-29T07:51:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![slcredentialmanager](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/slcredentialmanager/32/43984_2.png) [@slcredentialmanager](https://community.auth0.com/u/slcredentialmanager)\
**Post date:** [January 29, 2023, 7:51am UTC](https://community.auth0.com/t/need-help-on-creating-a-dynamic-callback-url/99222/1 "2023-01-29T07:51:20Z")

</div>

Hi, I am using NextJS project both running locally and on the cloud. I would like to have 2 separate callback URLs, so that I can choose to callback to localhost if NODE\_ENV is development and to callback to an https url when NODE\_ENV is production. Is there a way to do that for NextJS, or do I have to use 2 separate Auth0 applications?

---

<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:** [January 30, 2023, 7:54pm UTC](https://community.auth0.com/t/need-help-on-creating-a-dynamic-callback-url/99222/3 "2023-01-30T19:54:56Z")

</div>

Hi @slcredentialmanager,

Welcome to the Auth0 Community!

> [@slcredentialmanager](#):
>
> Is there a way to do that for NextJS, or do I have to use 2 separate Auth0 applications?

First, let me clarify that the `redirect_uri` parameter defines the destination after a user successfully logs in, which must match one of the URLs defined in the **Allowed Callback URLs** of your Application settings.

Given that, I recommend adding both Callback URLs to the list of Allowed Callback URLs for that app. Then to reach the different Callback URLs, you can specify them in the `redirect_uri`.

For example:

```auto
//Localhost
https://YOUR_DOMAIN/authorize?
    response_type=code&
    client_id=YOUR_CLIENT_ID&
    redirect_uri=http://localhost:3000/callback&
    scope={scope}&
    state={state}

```

```auto
//Cloud
https://YOUR_DOMAIN/authorize?
    response_type=code&
    client_id=YOUR_CLIENT_ID&
    redirect_uri=https://myexampleapp.com/callback&
    scope={scope}&
    state={state}

```

Reference: [Redirect Users](https://auth0.com/docs/authenticate/login/redirect-users-after-login)

I hope this helps!

Please let me know if there’s anything else I can do to help.

Thanks,

Rueben

---

<div class="post-metadata">

**Author:** ![slcredentialmanager](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/slcredentialmanager/32/43984_2.png) [@slcredentialmanager](https://community.auth0.com/u/slcredentialmanager)\
**Post date:** [February 1, 2023, 2:04am UTC](https://community.auth0.com/t/need-help-on-creating-a-dynamic-callback-url/99222/4 "2023-02-01T02:04:52Z")

</div>

Thanks, but my question relates more-so to how I would do this in NextJS, as there is little documentation on the handleAuth() API

---

<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 1, 2023, 7:55pm UTC](https://community.auth0.com/t/need-help-on-creating-a-dynamic-callback-url/99222/5 "2023-02-01T19:55:19Z")

</div>

Hi @slcredentialmanager,

Thank you for your response.

> [@slcredentialmanager](#):
>
> how I would do this in NextJS, as there is little documentation on the handleAuth() API

In the Next.JS SDK, you can pass a `returnTo` property to the handleLogin() handler of your preferred Callback URL. See below:

```auto
export default handleAuth({
  login: handleLogin({
    returnTo: 'YOUR_REDIRECT_URI' // Pass in your preferred callback URL
  })
});

```

Reference: [LoginOptions | @auth0/nextjs-auth0](https://auth0.github.io/nextjs-auth0/interfaces/handlers_login.LoginOptions.html#returnTo)

Please let me know how this goes for you.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![slcredentialmanager](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/slcredentialmanager/32/43984_2.png) [@slcredentialmanager](https://community.auth0.com/u/slcredentialmanager)\
**Post date:** [February 11, 2023, 10:12pm UTC](https://community.auth0.com/t/need-help-on-creating-a-dynamic-callback-url/99222/6 "2023-02-11T22:12:05Z")

</div>

Thanks @rueben.tiow. I actually ended up just changing the AUTH0\_BASE\_URL in production to point to my site URL. That ended up working

---

<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:** [February 25, 2023, 10:12pm UTC](https://community.auth0.com/t/need-help-on-creating-a-dynamic-callback-url/99222/7 "2023-02-25T22:12:27Z")

</div>

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