Migrating existing users to Privy
You can easily migrate users from your existing app into Privy. Privy supports
- real-time migration so you can map new users to Privy as they log in, as well as
- proactive migration to import user data into Privy all at once
Real-time migration
The simplest option is to "lazily" transfer your users to Privy: when an existing user logs in to your app via Privy for the first time, add their Privy DID to your internal users database to map between your existing user data and their Privy user object.
Namely, we suggest:
- In the your internal users database, add a 'Privy DID' column.
- In the
onSuccess
callback that runs afterlogin
, if theisNewUser
flag istrue
, make a request to your backend with the user's Privy DID (user.id
) and any account data you need to identify that user. For example, your request body might look like:
{
"address": user.wallet?.address,
"email": user.email?.address,
"privyDID": user.id
}
- When your backend receives the request from step (2), find the corresponding entry in your internal user database, matching on their wallet address, email address, or any other relevant account data.
- If entry does not have a "Privy DID", add the Privy DID from your request to the "Privy DID" column in your database.
- If the entry already has a "Privy DID" in your database, it should match the Privy DID included in your request. There is nothing more to do.
In this way, you can maintain a mapping between your existing user data and the corresponding Privy user object. Your user data will be updated as users interact with your app using Privy.
Direct import of user data
If your users have multiple linked accounts (e.g. email, wallet, Discord, etc.), we recommend you proactively migrate them into Privy to maintain those data links for your users. Please see the instructions here to migrate your existing users into Privy.