# Redirect user to a dynamic route which is basically its userId or organizationId got from IdToken

**URL:** <https://community.auth0.com/t/redirect-user-to-a-dynamic-route-which-is-basically-its-userid-or-organizationid-got-from-idtoken/132547>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [April 22, 2024, 6:28pm UTC](https://community.auth0.com/t/redirect-user-to-a-dynamic-route-which-is-basically-its-userid-or-organizationid-got-from-idtoken/132547 "2024-04-22T18:28:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![veshall](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/veshall/32/54392_2.png) [@veshall](https://community.auth0.com/u/veshall)\
**Post date:** [April 22, 2024, 6:28pm UTC](https://community.auth0.com/t/redirect-user-to-a-dynamic-route-which-is-basically-its-userid-or-organizationid-got-from-idtoken/132547/1 "2024-04-22T18:28:19Z")

</div>

I want to redirect user to a dynamic route in nextJs after the user athenticated i don’t from where it should be done like using api route or middleware.

here in “returnTo” i want the user to redirect to “/organization/[orgId]”.

> Blockquote

// app/api/auth/[auth0]/route.js  
import { handleAuth, handleLogin, handleLogout } from “@auth0/nextjs-auth0”;

export const GET = handleAuth({  
login: handleLogin({  
authorizationParams: {  
prompt: “login”,  
scope: process.env.AUTH0\_SCOPE,  
},  
returnTo: “/organization”, ← - - - - - here  
}),  
logout: handleLogout({  
authorizationParams: {  
prompt: “logout”,  
},  
returnTo: “/”,  
}),  
signup: handleLogin({ authorizationParams: { screen\_hint: “signup” } }),  
});

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [April 23, 2024, 2:59pm UTC](https://community.auth0.com/t/redirect-user-to-a-dynamic-route-which-is-basically-its-userid-or-organizationid-got-from-idtoken/132547/4 "2024-04-23T14:59:09Z")

</div>

Hi there @veshall , welcome back 🖐

In general, we can redirect users after the login only to the Allowed Callback URLs listed in the application’s settings:

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

For scenarios where dynamic callbacks are desired, we suggest providing one callback URL for all those /organization/[orgId] URLs and leveraging the state parameter during authentication.

Here, the concept is explained generically - [How do I set up a dynamic Allowed Callback URL?](https://community.auth0.com/t/how-do-i-set-up-a-dynamic-allowed-callback-url/60268)

I also found the topic where the `getLoginState` is used to redirect the user to the origin/referer URL but you may try to go analogically with your use case - [Redirecting back to starting page dynamically with nextjs-auth0](https://community.auth0.com/t/redirecting-back-to-starting-page-dynamically-with-nextjs-auth0/71460)

Here is the library reference: [LoginOptions | @auth0/nextjs-auth0](https://auth0.github.io/nextjs-auth0/interfaces/handlers_login.LoginOptions.html#returnTo)

Feel free to try this out, and please let us know if you have any follow-up questions along the way.

---

<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:** [May 7, 2024, 2:59pm UTC](https://community.auth0.com/t/redirect-user-to-a-dynamic-route-which-is-basically-its-userid-or-organizationid-got-from-idtoken/132547/5 "2024-05-07T14:59:26Z")

</div>

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