# Incorrect connection used in api?

**URL:** <https://community.auth0.com/t/incorrect-connection-used-in-api/94935>\
**Category:** Get Help\
**Tags:** regular-database-connections, connections\
**Created:** [November 22, 2022, 6:44pm UTC](https://community.auth0.com/t/incorrect-connection-used-in-api/94935 "2022-11-22T18:44:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![milangupta1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milangupta1/32/41439_2.png) [@milangupta1](https://community.auth0.com/u/milangupta1)\
**Post date:** [November 22, 2022, 6:44pm UTC](https://community.auth0.com/t/incorrect-connection-used-in-api/94935/1 "2022-11-22T18:44:04Z")

</div>

Hi, am pulling my hair out on this issue -

- I have 3 applications (test,dev,prod) with 3 separate connections (password stores), and I am using organizations.
- My test,dev&prod web applications are configured with the corresponding client\_id/secret and endpoints.
- I have added users and organizations and added the users to the organizations.
- I have enabled connections on organizations and have multiple connections (typically dev & test) enabled for an organization.

The problem -

1. For one user that I have added to the test environment, I am getting a login failure (incorrect password). The problem I am seeing, is the request log in Auth0 is showing the connection & connection\_id of the dev environment/application. The client\_id and name is correctly showing as the test application.  
… from the Auth0 monitoring log …  
“description”: “user auth0|637d08da911bxxxxxxxx is not part of the org\_esgTy2cROxxxxxxx organization”,  
“connection”: “meta-dev”,  
“connection\_id”: “con\_iXkOCb8xxxxxxx”,  
“client\_id”: “ltGgdmzMLVdc3CmKjnkyxxxxxxx”,  
“client\_name”: “Final (Test)”,  
…
2. Although I have added the user to the organization (although auto-membership on authentication is disabled), it is still saying the following (monitoring log) -  
“description”: “user auth0|637d08da911bcxxxxxx is not part of the org\_esgTy2cxxxxx organization”

I have double checked my application configs etc. I am able to log in with other IDs across my dev/test & prod environments/application … however, I think I am missing this gremlin.

I saw some other posts talking about “realms” etc. an area I haven’t yet studied … am I on the right path for diagnosis ? Any pointers/clues would be appreciated … trying to figure out exactly what is the behavior when using applications/connections/users/organizations across my dev/test/prod environments to ensure I don’t accidentally grant the wrong access to the wrong person …

Kind regards,  
Milan

---

<div class="post-metadata">

**Author:** ![milangupta1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milangupta1/32/41439_2.png) [@milangupta1](https://community.auth0.com/u/milangupta1)\
**Post date:** [November 22, 2022, 7:26pm UTC](https://community.auth0.com/t/incorrect-connection-used-in-api/94935/2 "2022-11-22T19:26:21Z")

</div>

Some additional info. I deleted the user and re-added the user in the dev app (connection). Am surprised that the user can now log in to dev, test & prod !!!

What is the right use of tenants/applications/connections/organizations ?

I have 1 application, 3 environments (dev/test/prod), many organizations (B2B customers), users that can be part of multiple organizations, users that can log into multiple environments (eg. developers can log into dev/test but may be restricted from prod), also, users that may be allowed into the organization for dev/test but not prod.

So, should I really be using 3 auth0 tenants (one for each environment) ? Or is my use (creating 3 applications) to segregate dev / test / prod users appropriate ?

Also, this does look like the limitation around “connection selection” option in the universal login, as, I am suspecting, auth0 is picking the first connection for an organization (in my case, the dev connection) … or am I missing a trick shot here ? Any help will be greatly appreciated.

Thanks in advance …

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 22, 2022, 9:58pm UTC](https://community.auth0.com/t/incorrect-connection-used-in-api/94935/3 "2022-11-22T21:58:32Z")

</div>

Hi there @milangupta1 welcome to the community!

> [@milangupta1](#):
>
> So, should I really be using 3 auth0 tenants (one for each environment) ? Or is my use (creating 3 applications) to segregate dev / test / prod users appropriate ?

In general Auth0 does recommend setting up multiple environments for dev, test, prod, etc.

> **[Set Up Multiple Environments](https://auth0.com/docs/get-started/auth0-overview/create-tenants/set-up-multiple-environments)**
>
> Describes how to use multiple Auth0 tenants to manage various environments.

> [@milangupta1](#):
>
> Also, this does look like the limitation around “connection selection” option in the universal login, as, I am suspecting, auth0 is picking the first connection for an organization (in my case, the dev connection) … or am I missing a trick shot here ? Any help will be greatly appreciated.

I’m not sure I fully understand your questions here - Once a user has been prompted with an Organization login (either by entering the Org in UL, OR has been directed to the login [otherwise](https://community.auth0.com/t/authenticating-users-through-a-specific-organization/84679)) If you can elaborate a bit on it I’d be happy to help!

---

<div class="post-metadata">

**Author:** ![milangupta1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milangupta1/32/41439_2.png) [@milangupta1](https://community.auth0.com/u/milangupta1)\
**Post date:** [November 23, 2022, 1:18am UTC](https://community.auth0.com/t/incorrect-connection-used-in-api/94935/5 "2022-11-23T01:18:06Z")

</div>

Thanks for the reply. I am going ahead and setting up 3 tenants. This of course has the downside of having to manage 3 tenants as well as having to create 3 users for each person etc. etc.

There are a couple of problems/mysteries I am seeing in a single tenant setup that if fixed, would have allowed for a single tenant setup supporting multiple environments in my use case.  
Specifically:

- The ability to select a connection from the universal login screen (i.e. after specifying the organization) - this would handle the case where an application is configured with multiple connections enabled on it.
- The mystery behavior where in the scenario (within a single tenant) -  
app1 → connection1 → user1  
app2 → connection2 → user2  
org1 → user1  
org2 → user2  
When I try to login to org2 using user2, it is looking for userid/password in connection1 and hence failing. I think this is because of the tenant level default connection setting. Whilst I ensured this is blank, I think auth0 is still picking the first available connection for the tenant (i.e. connection1) vs. the first available one configured for the application (client\_id/client\_secret).

BTW\> Am using elixir/phoenix with ueberauth i.e. api/callback.

Hope this explains it more clearly.

Kind regards / Thanks for your help.  
-M

---

<div class="post-metadata">

**Author:** ![milangupta1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milangupta1/32/41439_2.png) [@milangupta1](https://community.auth0.com/u/milangupta1)\
**Post date:** [November 23, 2022, 1:30am UTC](https://community.auth0.com/t/incorrect-connection-used-in-api/94935/6 "2022-11-23T01:30:37Z")

</div>

BTW\> This is also the reason why user1 was able to log into app2 (I think this is a security hole ?).

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 17, 2023, 11:56pm UTC](https://community.auth0.com/t/incorrect-connection-used-in-api/94935/7 "2023-02-17T23:56:00Z")

</div>


