# User returned with wrong identity (not belonging to current Connection)

**URL:** <https://community.auth0.com/t/user-returned-with-wrong-identity-not-belonging-to-current-connection/8636>\
**Category:** Get Help\
**Tags:** refresh\_token, identity\
**Created:** [October 31, 2017, 5:09pm UTC](https://community.auth0.com/t/user-returned-with-wrong-identity-not-belonging-to-current-connection/8636 "2017-10-31T17:09:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![emrah](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/emrah/32/6896_2.png) [@emrah](https://community.auth0.com/u/emrah)\
**Post date:** [October 31, 2017, 5:09pm UTC](https://community.auth0.com/t/user-returned-with-wrong-identity-not-belonging-to-current-connection/8636/1 "2017-10-31T17:09:11Z")

</div>

I have a setup where I have multiple Connections pointing to different custom databases. It seems like the users in one Connection is ignored. This is setup like this, because I have multiple environments, in this case: Staging and Production.

I fell over an issue when refreshing a token for some users. The user gets authenticated for the **Production** Connection, and gets the JWT (id\_token, refresh\_token, access\_token). Then later when requesting a new JWT by using the _refresh\_token_ the returned id\_token and access\_token doesn’t belong to **Production** connection but the **Staging** connection.

This is also re-produceable in the Auth0 Dashbard. When I search for a user with the same username in both environments, two things happen. - On mouse over, the user details link is exactly the same for both Connections. - On the user details page, even when clicking the user for Production Connection, the User Details page shows that the users identity is Staging.

**So my question is: is this intentional?**

I thought that each Connection was separate and users could exist in both with different details attached to their profile.

Images attached as examples. (Second image is when clicked on the Production user)  
 ![Connection](https://sea1.discourse-cdn.com/auth0/storage/temp/616-auth01.png)

![Detail](https://sea1.discourse-cdn.com/auth0/storage/temp/617-auth02.png)

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [October 31, 2017, 10:40pm UTC](https://community.auth0.com/t/user-returned-with-wrong-identity-not-belonging-to-current-connection/8636/2 "2017-10-31T22:40:20Z")

</div>

There’s a few things worth mentioning here; the most important is that by default with regular database connections each user will receive a tenant/domain wide unique user identifier. However, with a custom database connection you (the custom database scripts) are responsible to ensure that the user identifier is unique across connections. A simple approach would be to use a unique prefix per each connection.

Based on what you describe it sounds like both users were using the same user identifier so the custom database connections did not meet the uniqueness requirement.

Finally, you mention you’re using separate connection in order to have a distinction between production and staging. Although connections give some degree of isolation between users, the recommended approach for having a development or staging environment would be to use a completely different tenant/domain; see more information about this at: [Set Up Multiple Environments](https://auth0.com/docs/dev-lifecycle/setting-up-env)

---

<div class="post-metadata">

**Author:** ![emrah](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/emrah/32/6896_2.png) [@emrah](https://community.auth0.com/u/emrah)\
**Post date:** [October 31, 2017, 10:56pm UTC](https://community.auth0.com/t/user-returned-with-wrong-identity-not-belonging-to-current-connection/8636/3 "2017-10-31T22:56:06Z")

</div>

Thanks @jmangelo - I was unaware of the _uniqueness requirement_. I’ll update my scripts with a prefix as you mentioned.

---

<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 2, 2018, 5:57am UTC](https://community.auth0.com/t/user-returned-with-wrong-identity-not-belonging-to-current-connection/8636/4 "2018-03-02T05:57:14Z")

</div>


