# Auth0 Beginner - What is the recommended best practice for synchronizing users with external databases?

**URL:** <https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [November 26, 2023, 11:58pm UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670 "2023-11-26T23:58:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![viniciusteixeiradias](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/viniciusteixeiradias/32/52741_2.png) [@viniciusteixeiradias](https://community.auth0.com/u/viniciusteixeiradias)\
**Post date:** [November 26, 2023, 11:58pm UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670/1 "2023-11-26T23:58:11Z")

</div>

I am developing an application using Vue.js (+Universal Login Auth0), Node.js, and a specific database. My goal is to integrate users created in Auth0 with my database, ensuring synchronization of information. In case of errors during user creation in Auth0 or in my own database, I want to execute a rollback to prevent data desynchronization between the two databases.

I would like to know if there are recommended best practices for this implementation or if there is a step-by-step guide that I can follow.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 29, 2023, 8:38pm UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670/3 "2023-11-29T20:38:11Z")

</div>

Hi @viniciusteixeiradias,

Welcome to the Auth0 Community!

There are different ways to approach synchronizing your external user DB with the Auth0 user store.

- You can use periodic syncing via [Bulk User Exports](https://auth0.com/docs/manage-users/user-migration/bulk-user-exports) or [Manage Users Using the Management API](https://auth0.com/docs/manage-users/user-accounts/manage-users-using-the-management-api)
- Sync on login via [Login Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow) Actions (be careful, this runs on every authentication and requests can slow down your login flow)
- Or sync with your DB when you receive a valid token in your app.

Alternatively, you can use your DB as the source of truth with [Custom Database Connections](https://auth0.com/docs/authenticate/database-connections/custom-db), but this will limit you to only username/password connection and no third party IdPs like Google or Github.

Let me know if you have any questions.

---

<div class="post-metadata">

**Author:** ![viniciusteixeiradias](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/viniciusteixeiradias/32/52741_2.png) [@viniciusteixeiradias](https://community.auth0.com/u/viniciusteixeiradias)\
**Post date:** [November 30, 2023, 12:49am UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670/4 "2023-11-30T00:49:45Z")

</div>

Hi @dan.woda , thanks for your help, now the process is clearer.

I still have some questions but it’s about another subject, I’ll look in the community posts or maybe I’ll open a new discussion for that.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 30, 2023, 1:54pm UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670/5 "2023-11-30T13:54:34Z")

</div>

Perfect. Hope that was helpful!

---

<div class="post-metadata">

**Author:** ![antony.a](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/antony.a/32/49208_2.png) [@antony.a](https://community.auth0.com/u/antony.a)\
**Post date:** [December 14, 2023, 5:12am UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670/6 "2023-12-14T05:12:07Z")

</div>

The login flow will only be executed when a user logs in. Other requests, such as fetching projects through an API, will not be affected, correct?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 14, 2023, 4:34pm UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670/7 "2023-12-14T16:34:46Z")

</div>

The post login action trigger is executed when a user authentication occurs. For example:

- Interactive login
- Refresh token exchange
- Silent user authentication

---

<div class="post-metadata">

**Author:** ![antony.a](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/antony.a/32/49208_2.png) [@antony.a](https://community.auth0.com/u/antony.a)\
**Post date:** [December 15, 2023, 6:35am UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670/8 "2023-12-15T06:35:57Z")

</div>

Thank you for the reply , Now i am going to use postlogin action ,  
So i want user orgnizationId for store into my db i have an one api to create user ,  
But i need userId , email and organizationId .  
I get userId and email using event but I don’t know how to get organizationId ?

 ![Screenshot 2023-12-15 120507](https://global.discourse-cdn.com/auth0/original/3X/b/b/bb9319b1c6031ec18c4651a3dff89313135a12cb.png)  
 ![Screenshot 2023-12-15 120526](https://global.discourse-cdn.com/auth0/original/3X/f/d/fda191069e6587831f9809d7677e58b0458963f7.png)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 19, 2023, 3:18pm UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670/9 "2023-12-19T15:18:43Z")

</div>

If the `event.organization` object is undefined, it’s likely that the user has not logged in with an organization during this login transaction.

---

<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:** [January 2, 2024, 3:19pm UTC](https://community.auth0.com/t/auth0-beginner-what-is-the-recommended-best-practice-for-synchronizing-users-with-external-databases/121670/10 "2024-01-02T15:19:30Z")

</div>

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