# Redirect users to organization specific subdomain after login

**URL:** <https://community.auth0.com/t/redirect-users-to-organization-specific-subdomain-after-login/102200>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [March 9, 2023, 8:01pm UTC](https://community.auth0.com/t/redirect-users-to-organization-specific-subdomain-after-login/102200 "2023-03-09T20:01:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chan.lee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chan.lee/32/45299_2.png) [@chan.lee](https://community.auth0.com/u/chan.lee)\
**Post date:** [March 9, 2023, 8:01pm UTC](https://community.auth0.com/t/redirect-users-to-organization-specific-subdomain-after-login/102200/1 "2023-03-09T20:01:59Z")

</div>

Hello,

I am setting up a B2B application where customer applications are hosted on their own subdomain (e.g. `companyA.myapp.com`, `companyB.myapp.com`)

These are currently treated as different applications and users navigate to their subdomain, get kicked to the Auth0 login flow, then get redirected back to the original subdomain.

I would like to move this to a “universal” login page where users can go to any subdomain and login with their organization, user, and password, then get redirected to their subdomain.

I’ve gotten started with organizations but I can’t figure out how to do the redirect.

I’m using the “New Universal Login Experience” and this library [react-oidc-context - npm](https://www.npmjs.com/package/react-oidc-context) in my application like so:

```auto
      <AuthProvider
        authority={config.oauth.authority}
        client_id={config.oauth.clientId}
        redirect_uri={window.location.origin}
        ...
      >
        <BrowserRouter>
          <Main />
        </BrowserRouter>
      </AuthProvider>

```

Now when the user goes to log in, they are first prompted for their organization, then get directed to their organization-specific login page.

But after logging in, they get redirected back to the original `redirect_uri`. For example:

1. `UserA@companyA.org` navigates to `companyB.myapp.com`
2. `UserA@companyA.org` gets redirected to Auth0 for login
3. `UserA@companyA.org` enters in organization `companyA`
4. `UserA@companyA.org` gets redirected to the organization-specific login page
5. `UserA@companyA.org` enters in their credentials
6. `UserA@companyA.org` gets redirected back to `companyB.myapp.com`

The desired behavior is to have step 6 redirect the user to `companyA.myapp.com`.

I’ve tried using actions to redirect the user ([Redirect with Actions](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/redirect-with-actions)) but this doesn’t accomplish this since it only delays the inevitable redirect back to the original `redirect_uri`.

Is there a way to get this to work?

---

<div class="post-metadata">

**Author:** ![nathan.jenkins](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nathan.jenkins/32/44577_2.png) [@nathan.jenkins](https://community.auth0.com/u/nathan.jenkins)\
**Post date:** [March 10, 2023, 10:35pm UTC](https://community.auth0.com/t/redirect-users-to-organization-specific-subdomain-after-login/102200/2 "2023-03-10T22:35:26Z")

</div>

Hi @chan.lee , Welcome to the Auth0 community!

Thanks for the explanation, I believe this redirect can all be handled by Auth0 using [Subdomain URL Placeholders](https://auth0.com/docs/get-started/applications/wildcards-for-subdomains) within the Application Callback URL.  
On this page, [here](https://auth0.com/docs/get-started/applications/wildcards-for-subdomains#organization-url-placeholders), you can see there is the {organization\_name} placeholder that can be used.  
I hope this info provides the solution you are looking for, thanks!

---

<div class="post-metadata">

**Author:** ![chan.lee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chan.lee/32/45299_2.png) [@chan.lee](https://community.auth0.com/u/chan.lee)\
**Post date:** [March 13, 2023, 2:18pm UTC](https://community.auth0.com/t/redirect-users-to-organization-specific-subdomain-after-login/102200/3 "2023-03-13T14:18:43Z")

</div>

Hi @nathan.jenkins

Thanks for the reply. I’ve tried using `{organization_name}` but it still requires you to know the final subdomain _before_ initiating the auth flow.

In my provided example, if `UserA@companyA.org` navigates to `companyB.myapp.com`, `redirect_uri` gets set to `companyB.myapp.com` and I can not find a way to change that to `companyA.myapp.com`, even if the user inputs `companyA` in the organization prompt.

Is there a way to get around this limitation?

---

<div class="post-metadata">

**Author:** ![chan.lee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chan.lee/32/45299_2.png) [@chan.lee](https://community.auth0.com/u/chan.lee)\
**Post date:** [March 14, 2023, 1:30pm UTC](https://community.auth0.com/t/redirect-users-to-organization-specific-subdomain-after-login/102200/4 "2023-03-14T13:30:11Z")

</div>

I’ve tried the adjusting the project to do the following but still running into issues:

- Updated all subdomains to redirect to `myapp.com` if the user is not authenticated
- Updated `myapp.com` to use [GitHub - auth0/auth0-react: Auth0 SDK for React Single Page Applications (SPA)](https://github.com/auth0/auth0-react)
- Configured `AuthProvider` to use `cookieDomain=.myapp.com`
- Updated `myapp.com` to redirect to correct subdomain after authentication

I can see that there are a few cookies set (`organization_hint` and `is.authenticated`) and transferred to the subdomain but I still get kicked to the login page.

---

<div class="post-metadata">

**Author:** ![chan.lee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chan.lee/32/45299_2.png) [@chan.lee](https://community.auth0.com/u/chan.lee)\
**Post date:** [March 15, 2023, 1:44pm UTC](https://community.auth0.com/t/redirect-users-to-organization-specific-subdomain-after-login/102200/5 "2023-03-15T13:44:18Z")

</div>

I raised an issue on the `auth0-react` project and a developer on the project pointed out a critical Auth0 cookie was not being transferred on redirect due to my browser settings: [`cookieDomain` doesn't seem to share auth between (sub)domains · Issue #523 · auth0/auth0-react · GitHub](https://github.com/auth0/auth0-react/issues/523)

Switching my Chrome cookie settings from “Block third-party cookies” to “Allow all cookies” fixed my issues and everything is now working as expected.

---

<div class="post-metadata">

**Author:** ![nathan.jenkins](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nathan.jenkins/32/44577_2.png) [@nathan.jenkins](https://community.auth0.com/u/nathan.jenkins)\
**Post date:** [March 18, 2023, 7:49pm UTC](https://community.auth0.com/t/redirect-users-to-organization-specific-subdomain-after-login/102200/6 "2023-03-18T19:49:23Z")

</div>

Hi @chan.lee ,  
Great to hear that it’s working now, and thank you very much for providing that information here!

---

<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 1, 2023, 7:50pm UTC](https://community.auth0.com/t/redirect-users-to-organization-specific-subdomain-after-login/102200/7 "2023-04-01T19:50:09Z")

</div>

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