> For the complete documentation index, see [llms.txt](https://docs.tryterra.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tryterra.co/help-center/help-topics/no-data/auth-scopes-user-id-matching/reauth-webhook-user-id-changes.md).

# How do I handle a changed Terra user ID after reauth?

A reconnect issues a new Terra user ID, and user\_reauth links it to the old one only if the old connection was still active on the same provider account when the user reconnected.

**A reconnect issues a new Terra user ID, and a `user_reauth` webhook links it to the old one only if the old connection was still active on the same provider account when the user reconnected.** When the user reconnects the same provider under the same `reference_id` while the previous connection is active, Terra deletes the old connection and sends an `auth` webhook for the new user plus a `user_reauth` webhook with `old_user` and `new_user` objects.

**Add handling for `user_reauth`:**

* Use `old_user.user_id` and `new_user.user_id` to **map the new id to the previous one** (stitching historic data across reauths without needing a fresh backfill).
* **Treat it like a deauth of the old id.** The old user ID no longer receives data.

**If the old connection was removed first, there is no `user_reauth`.** For example, if your app calls `/auth/deauthenticateUser` and the user reconnects later, you receive a `deauth` for the old user ID and an `auth` for a new one, with nothing linking the two. Handle `deauth` and `auth` as well as `user_reauth`, and key your records on your stable `reference_id` so the new user ID can be matched.

A common cause of reconnects appearing to 'not work' is the reauth flow **not reusing the original `reference_id`**: a new `reference_id` creates a new Terra user and orphans the old one, so key the widget call on a stable internal user ID. See [handling authentication events](https://docs.tryterra.co/unified-api/user-authentication/handling-authentication-events) and [event types](https://docs.tryterra.co/reference/health-and-fitness-api/event-types).
